From cd65203ad740906f1a89008b4602e1fe8fecf7aa Mon Sep 17 00:00:00 2001 From: Christian Gendreau Date: Wed, 20 Nov 2024 15:53:24 -0500 Subject: [PATCH 1/6] 35276 Add Metagenomic Workflow resource Added db migration and entities --- .../seqdb/api/entities/MetagenomicsBatch.java | 68 +++++++++++++++++ .../api/entities/MetagenomicsBatchItem.java | 75 +++++++++++++++++++ .../db/changelog/db.changelog-master.xml | 1 + .../migrations/54-Add_metagenomics_tables.xml | 58 ++++++++++++++ 4 files changed, 202 insertions(+) create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatch.java create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.java create mode 100644 src/main/resources/db/changelog/migrations/54-Add_metagenomics_tables.xml diff --git a/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatch.java b/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatch.java new file mode 100644 index 00000000..eb2a175f --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatch.java @@ -0,0 +1,68 @@ +package ca.gc.aafc.seqdb.api.entities; + +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; +import org.hibernate.annotations.NaturalId; + +import ca.gc.aafc.dina.entity.DinaEntity; +import ca.gc.aafc.seqdb.api.entities.libraryprep.IndexSet; + +import java.time.OffsetDateTime; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Entity +@Builder +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "metagenomics_batch") +public class MetagenomicsBatch implements DinaEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @NotNull + @NaturalId + private UUID uuid; + + @NotBlank + @Column(name = "created_by", updatable = false) + private String createdBy; + + @Column(name = "created_on", insertable = false, updatable = false) + @Generated(value = GenerationTime.INSERT) + private OffsetDateTime createdOn; + + @Column(name = "_group") + private String group; + + @NotBlank + @Size(max = 100) + private String name; + + private UUID protocol; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "index_set_id") + private IndexSet indexSet; + +} 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 new file mode 100644 index 00000000..b49c997a --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.java @@ -0,0 +1,75 @@ +package ca.gc.aafc.seqdb.api.entities; + +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; +import org.hibernate.annotations.NaturalId; + +import ca.gc.aafc.dina.entity.DinaEntity; +import ca.gc.aafc.seqdb.api.entities.libraryprep.NgsIndex; + +import java.time.OffsetDateTime; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Entity +@Builder +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Table(name = "metagenomics_batch_item") +public class MetagenomicsBatchItem implements DinaEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @NotNull + @NaturalId + private UUID uuid; + + @NotBlank + @Column(name = "created_by", updatable = false) + private String createdBy; + + @Column(name = "created_on", insertable = false, updatable = false) + @Generated(value = GenerationTime.INSERT) + private OffsetDateTime createdOn; + + // eager since we need it for group-based permission + @ManyToOne(fetch = FetchType.EAGER) + @JoinColumn(name = "metagenomics_batch_id") + private MetagenomicsBatch metagenomicsBatch; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "indexi5_id") + private NgsIndex indexI5; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "indexi7_id") + private NgsIndex indexI7; + + @Override + public String getGroup() { + if (metagenomicsBatch == null) { + return null; + } + return metagenomicsBatch.getGroup(); + } + +} diff --git a/src/main/resources/db/changelog/db.changelog-master.xml b/src/main/resources/db/changelog/db.changelog-master.xml index dc1ac0aa..97de9032 100644 --- a/src/main/resources/db/changelog/db.changelog-master.xml +++ b/src/main/resources/db/changelog/db.changelog-master.xml @@ -58,4 +58,5 @@ + 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 new file mode 100644 index 00000000..ac068296 --- /dev/null +++ b/src/main/resources/db/changelog/migrations/54-Add_metagenomics_tables.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 9f7287cb766d94675c9ac259769571d7b965763b Mon Sep 17 00:00:00 2001 From: Christian Gendreau Date: Thu, 21 Nov 2024 15:09:18 -0500 Subject: [PATCH 2/6] 35276 Add Metagenomic Workflow resource Added dtos and repository --- .../seqdb/api/dto/MetagenomicsBatchDto.java | 45 ++++++++++++++++ .../api/dto/MetagenomicsBatchItemDto.java | 42 +++++++++++++++ .../MetagenomicsBatchItemRepository.java | 51 +++++++++++++++++++ .../MetagenomicsBatchRepository.java | 51 +++++++++++++++++++ .../service/MetagenomicsBatchItemService.java | 27 ++++++++++ .../api/service/MetagenomicsBatchService.java | 26 ++++++++++ .../aafc/seqdb/api/SequenceModuleBaseIT.java | 9 ++++ .../api/entities/MetagenomicsBatchIT.java | 28 ++++++++++ .../api/repository/MetagenomicsBatchIT.java | 31 +++++++++++ .../factories/MetagenomicsBatchFactory.java | 21 ++++++++ .../MetagenomicsBatchItemFactory.java | 24 +++++++++ .../MetagenomicsBatchItemTestFixture.java | 12 +++++ .../MetagenomicsBatchTestFixture.java | 17 +++++++ 13 files changed, 384 insertions(+) create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchDto.java create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.java create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchRepository.java create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchItemService.java create mode 100644 src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchService.java create mode 100644 src/test/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchIT.java create mode 100644 src/test/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchIT.java create mode 100644 src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchFactory.java create mode 100644 src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchItemFactory.java create mode 100644 src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchItemTestFixture.java create mode 100644 src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchTestFixture.java diff --git a/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchDto.java b/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchDto.java new file mode 100644 index 00000000..d89477bb --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchDto.java @@ -0,0 +1,45 @@ +package ca.gc.aafc.seqdb.api.dto; + +import ca.gc.aafc.dina.dto.ExternalRelationDto; +import ca.gc.aafc.dina.dto.RelatedEntity; +import ca.gc.aafc.dina.repository.meta.JsonApiExternalRelation; +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatch; + +import io.crnk.core.resource.annotations.JsonApiId; +import io.crnk.core.resource.annotations.JsonApiRelation; +import io.crnk.core.resource.annotations.JsonApiResource; +import java.time.OffsetDateTime; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonApiResource(type = MetagenomicsBatchDto.TYPENAME) +@RelatedEntity(MetagenomicsBatch.class) +public class MetagenomicsBatchDto { + + public static final String TYPENAME = "metagenomics-batch"; + + @JsonApiId + private UUID uuid; + + private String createdBy; + + private OffsetDateTime createdOn; + private String group; + + private String name; + + @JsonApiExternalRelation(type = "protocol") + @JsonApiRelation + private ExternalRelationDto protocol; + + @JsonApiRelation + private IndexSetDto indexSet; + +} 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 new file mode 100644 index 00000000..0cb4d961 --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.java @@ -0,0 +1,42 @@ +package ca.gc.aafc.seqdb.api.dto; + +import ca.gc.aafc.dina.dto.RelatedEntity; +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatchItem; + +import io.crnk.core.resource.annotations.JsonApiId; +import io.crnk.core.resource.annotations.JsonApiRelation; +import io.crnk.core.resource.annotations.JsonApiResource; +import java.time.OffsetDateTime; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonApiResource(type = MetagenomicsBatchItemDto.TYPENAME) +@RelatedEntity(MetagenomicsBatchItem.class) +public class MetagenomicsBatchItemDto { + + public static final String TYPENAME = "metagenomics-batch-item"; + + @JsonApiId + private UUID uuid; + + private String createdBy; + + private OffsetDateTime createdOn; + + @JsonApiRelation + private MetagenomicsBatchDto metagenomicsBatch; + + @JsonApiRelation + private NgsIndexDto indexI5; + + @JsonApiRelation + private NgsIndexDto indexI7; + +} diff --git a/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java b/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java new file mode 100644 index 00000000..fe84e27e --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java @@ -0,0 +1,51 @@ +package ca.gc.aafc.seqdb.api.repository; + +import org.springframework.boot.info.BuildProperties; +import org.springframework.stereotype.Repository; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import ca.gc.aafc.dina.mapper.DinaMapper; +import ca.gc.aafc.dina.repository.DinaRepository; +import ca.gc.aafc.dina.repository.external.ExternalResourceProvider; +import ca.gc.aafc.dina.security.DinaAuthenticatedUser; +import ca.gc.aafc.dina.security.auth.DinaAuthorizationService; +import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchItemDto; +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatchItem; +import ca.gc.aafc.seqdb.api.service.MetagenomicsBatchItemService; + +import java.util.Optional; +import lombok.NonNull; + +@Repository +public class MetagenomicsBatchItemRepository extends DinaRepository { + + private Optional dinaAuthenticatedUser; + + public MetagenomicsBatchItemRepository( + @NonNull MetagenomicsBatchItemService dinaService, + DinaAuthorizationService groupAuthorizationService, + @NonNull BuildProperties props, + ExternalResourceProvider externalResourceProvider, + Optional dinaAuthenticatedUser, + ObjectMapper objMapper) { + super( + dinaService, + groupAuthorizationService, + Optional.empty(), + new DinaMapper<>(MetagenomicsBatchItemDto.class), + MetagenomicsBatchItemDto.class, + MetagenomicsBatchItem.class, + null, + externalResourceProvider, + props, objMapper); + this.dinaAuthenticatedUser = dinaAuthenticatedUser; + } + + @Override + public S create(S resource) { + dinaAuthenticatedUser.ifPresent( + authenticatedUser -> resource.setCreatedBy(authenticatedUser.getUsername())); + return super.create(resource); + } +} \ No newline at end of file diff --git a/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchRepository.java b/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchRepository.java new file mode 100644 index 00000000..76aa18c2 --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchRepository.java @@ -0,0 +1,51 @@ +package ca.gc.aafc.seqdb.api.repository; + +import org.springframework.boot.info.BuildProperties; +import org.springframework.stereotype.Repository; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import ca.gc.aafc.dina.mapper.DinaMapper; +import ca.gc.aafc.dina.repository.DinaRepository; +import ca.gc.aafc.dina.repository.external.ExternalResourceProvider; +import ca.gc.aafc.dina.security.DinaAuthenticatedUser; +import ca.gc.aafc.dina.security.auth.DinaAuthorizationService; +import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchDto; +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatch; +import ca.gc.aafc.seqdb.api.service.MetagenomicsBatchService; + +import java.util.Optional; +import lombok.NonNull; + +@Repository +public class MetagenomicsBatchRepository extends DinaRepository { + + private Optional dinaAuthenticatedUser; + + public MetagenomicsBatchRepository( + @NonNull MetagenomicsBatchService dinaService, + DinaAuthorizationService groupAuthorizationService, + @NonNull BuildProperties props, + ExternalResourceProvider externalResourceProvider, + Optional dinaAuthenticatedUser, + ObjectMapper objMapper) { + super( + dinaService, + groupAuthorizationService, + Optional.empty(), + new DinaMapper<>(MetagenomicsBatchDto.class), + MetagenomicsBatchDto.class, + MetagenomicsBatch.class, + null, + externalResourceProvider, + props, objMapper); + this.dinaAuthenticatedUser = dinaAuthenticatedUser; + } + + @Override + public S create(S resource) { + dinaAuthenticatedUser.ifPresent( + authenticatedUser -> resource.setCreatedBy(authenticatedUser.getUsername())); + return super.create(resource); + } +} diff --git a/src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchItemService.java b/src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchItemService.java new file mode 100644 index 00000000..611cc728 --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchItemService.java @@ -0,0 +1,27 @@ +package ca.gc.aafc.seqdb.api.service; + +import lombok.NonNull; + +import org.springframework.stereotype.Service; +import org.springframework.validation.SmartValidator; + +import ca.gc.aafc.dina.jpa.BaseDAO; +import ca.gc.aafc.dina.service.DefaultDinaService; +import ca.gc.aafc.dina.util.UUIDHelper; +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatchItem; + +@Service +public class MetagenomicsBatchItemService extends DefaultDinaService { + + public MetagenomicsBatchItemService( + @NonNull BaseDAO baseDAO, @NonNull SmartValidator sv) { + super(baseDAO, sv); + } + + @Override + protected void preCreate(MetagenomicsBatchItem entity) { + entity.setUuid(UUIDHelper.generateUUIDv7()); + } + +} + diff --git a/src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchService.java b/src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchService.java new file mode 100644 index 00000000..fb5ef2df --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchService.java @@ -0,0 +1,26 @@ +package ca.gc.aafc.seqdb.api.service; + +import lombok.NonNull; + +import org.springframework.stereotype.Service; +import org.springframework.validation.SmartValidator; + +import ca.gc.aafc.dina.jpa.BaseDAO; +import ca.gc.aafc.dina.service.DefaultDinaService; +import ca.gc.aafc.dina.util.UUIDHelper; +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatch; + +@Service +public class MetagenomicsBatchService extends DefaultDinaService { + + public MetagenomicsBatchService( + @NonNull BaseDAO baseDAO, @NonNull SmartValidator sv) { + super(baseDAO, sv); + } + + @Override + protected void preCreate(MetagenomicsBatch entity) { + entity.setUuid(UUIDHelper.generateUUIDv7()); + } + +} diff --git a/src/test/java/ca/gc/aafc/seqdb/api/SequenceModuleBaseIT.java b/src/test/java/ca/gc/aafc/seqdb/api/SequenceModuleBaseIT.java index 6cbd7348..cc735c59 100644 --- a/src/test/java/ca/gc/aafc/seqdb/api/SequenceModuleBaseIT.java +++ b/src/test/java/ca/gc/aafc/seqdb/api/SequenceModuleBaseIT.java @@ -4,6 +4,8 @@ import ca.gc.aafc.seqdb.api.service.GenericMolecularAnalysisService; import ca.gc.aafc.seqdb.api.service.GenericMolecularAnalysisItemService; +import ca.gc.aafc.seqdb.api.service.MetagenomicsBatchItemService; +import ca.gc.aafc.seqdb.api.service.MetagenomicsBatchService; import ca.gc.aafc.seqdb.api.service.MolecularAnalysisResultService; import ca.gc.aafc.seqdb.api.service.MolecularAnalysisRunItemService; import ca.gc.aafc.seqdb.api.service.MolecularAnalysisRunService; @@ -40,4 +42,11 @@ public class SequenceModuleBaseIT extends BaseIntegrationTest { @Inject protected GenericMolecularAnalysisItemService genericMolecularAnalysisItemService; + + @Inject + protected MetagenomicsBatchService metagenomicsBatchService; + + @Inject + protected MetagenomicsBatchItemService metagenomicsBatchItemService; + } diff --git a/src/test/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchIT.java b/src/test/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchIT.java new file mode 100644 index 00000000..de3194ae --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchIT.java @@ -0,0 +1,28 @@ +package ca.gc.aafc.seqdb.api.entities; + +import org.junit.jupiter.api.Test; + +import ca.gc.aafc.seqdb.api.SequenceModuleBaseIT; +import ca.gc.aafc.seqdb.api.testsupport.factories.IndexSetFactory; +import ca.gc.aafc.seqdb.api.testsupport.factories.MetagenomicsBatchFactory; +import ca.gc.aafc.seqdb.api.testsupport.factories.MetagenomicsBatchItemFactory; +import ca.gc.aafc.seqdb.api.testsupport.factories.NgsIndexFactory; + +public class MetagenomicsBatchIT extends SequenceModuleBaseIT { + + @Test + public void onCreateMetagenomicsBatchEntities_entitiesSaved() { + MetagenomicsBatch mgb = MetagenomicsBatchFactory.newMetagenomicsBatch() + .indexSet(IndexSetFactory.newIndexSet().build()) + .build(); + metagenomicsBatchService.create(mgb); + + MetagenomicsBatchItem mgbi = MetagenomicsBatchItemFactory.newMetagenomicsBatchItem(mgb) + .indexI5(NgsIndexFactory.newNgsIndex().build()) + .indexI7(NgsIndexFactory.newNgsIndex().build()) + .build(); + + metagenomicsBatchItemService.create(mgbi); + } +} + 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 new file mode 100644 index 00000000..bf3c5caf --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchIT.java @@ -0,0 +1,31 @@ +package ca.gc.aafc.seqdb.api.repository; + +import org.junit.jupiter.api.Test; + +import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchDto; +import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchItemDto; +import ca.gc.aafc.seqdb.api.testsupport.fixtures.MetagenomicsBatchItemTestFixture; +import ca.gc.aafc.seqdb.api.testsupport.fixtures.MetagenomicsBatchTestFixture; + +import javax.inject.Inject; + +public class MetagenomicsBatchIT extends BaseRepositoryTestV2 { + + @Inject + private MetagenomicsBatchRepository metagenomicsBatchRepository; + + @Inject + private MetagenomicsBatchItemRepository metagenomicsBatchItemRepository; + + @Test + public void onValidDto_dtoSavedWithoutExceptions() { + + MetagenomicsBatchDto genericMolecularAnalysisDto = metagenomicsBatchRepository + .create(MetagenomicsBatchTestFixture.newMetagenomicsBatch()); + + MetagenomicsBatchItemDto itemDto = MetagenomicsBatchItemTestFixture.newMetagenomicsBatchItem(); + itemDto.setMetagenomicsBatch(genericMolecularAnalysisDto); + + metagenomicsBatchItemRepository.create(itemDto); + } +} diff --git a/src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchFactory.java b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchFactory.java new file mode 100644 index 00000000..b1bfdf2b --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchFactory.java @@ -0,0 +1,21 @@ +package ca.gc.aafc.seqdb.api.testsupport.factories; + +import java.util.UUID; + +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatch; + +public final class MetagenomicsBatchFactory { + + private MetagenomicsBatchFactory() { + // static utility class + } + + public static MetagenomicsBatch.MetagenomicsBatchBuilder newMetagenomicsBatch() { + + return MetagenomicsBatch.builder() + .uuid(UUID.randomUUID()) + .createdBy("test user") + .name(TestableEntityFactory.generateRandomName(10)) + .group("dina"); + } +} diff --git a/src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchItemFactory.java b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchItemFactory.java new file mode 100644 index 00000000..ab176863 --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/factories/MetagenomicsBatchItemFactory.java @@ -0,0 +1,24 @@ +package ca.gc.aafc.seqdb.api.testsupport.factories; + +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatch; +import ca.gc.aafc.seqdb.api.entities.MetagenomicsBatchItem; + +import java.util.UUID; + +public final class MetagenomicsBatchItemFactory { + + private MetagenomicsBatchItemFactory() { + // static utility class + } + + public static MetagenomicsBatchItem.MetagenomicsBatchItemBuilder newMetagenomicsBatchItem( + MetagenomicsBatch metagenomicsBatch) { + + return MetagenomicsBatchItem.builder() + .uuid(UUID.randomUUID()) + .createdBy("test user") + .metagenomicsBatch(metagenomicsBatch); + } +} + + 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 new file mode 100644 index 00000000..2ac6b8f2 --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchItemTestFixture.java @@ -0,0 +1,12 @@ +package ca.gc.aafc.seqdb.api.testsupport.fixtures; + +import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchItemDto; + +public class MetagenomicsBatchItemTestFixture { + + public static MetagenomicsBatchItemDto newMetagenomicsBatchItem() { + return MetagenomicsBatchItemDto.builder() + .createdBy("test-user") + .build(); + } +} diff --git a/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchTestFixture.java b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchTestFixture.java new file mode 100644 index 00000000..1888746c --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchTestFixture.java @@ -0,0 +1,17 @@ +package ca.gc.aafc.seqdb.api.testsupport.fixtures; + +import ca.gc.aafc.seqdb.api.dto.MetagenomicsBatchDto; +import ca.gc.aafc.seqdb.api.testsupport.factories.TestableEntityFactory; + +public class MetagenomicsBatchTestFixture { + + public static final String GROUP = "aafc"; + + public static MetagenomicsBatchDto newMetagenomicsBatch() { + return MetagenomicsBatchDto.builder() + .group(GROUP) + .name(TestableEntityFactory.generateRandomName(12)) + .createdBy("test-user") + .build(); + } +} From afc00d1f2d3cac1945aebfe064978aec3e34ce79 Mon Sep 17 00:00:00 2001 From: Christian Gendreau Date: Thu, 21 Nov 2024 15:28:02 -0500 Subject: [PATCH 3/6] Fixed Checkstyle --- .../seqdb/api/repository/MetagenomicsBatchItemRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java b/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java index fe84e27e..37c2be3f 100644 --- a/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java +++ b/src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.java @@ -48,4 +48,4 @@ public S create(S resource) { authenticatedUser -> resource.setCreatedBy(authenticatedUser.getUsername())); return super.create(resource); } -} \ No newline at end of file +} From 380d87f67e480bd9ad3b76549e8d68441171344a Mon Sep 17 00:00:00 2001 From: Christian Gendreau Date: Wed, 27 Nov 2024 08:36:54 -0500 Subject: [PATCH 4/6] 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); From cd2f6bdf2c6d586db83f3757c0d6920f19c2c4b0 Mon Sep 17 00:00:00 2001 From: John Phan Date: Fri, 29 Nov 2024 09:29:37 -0800 Subject: [PATCH 5/6] Added MolecularAnalysisRunItem relationship to MetagenomicsBatchItem --- .../api/dto/MetagenomicsBatchItemDto.java | 7 +++ .../api/entities/MetagenomicsBatchItem.java | 4 ++ .../migrations/54-Add_metagenomics_tables.xml | 44 +++++++++++-------- .../api/repository/MetagenomicsBatchIT.java | 31 ++++++++++++- 4 files changed, 67 insertions(+), 19 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 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..3c31367e 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); } From 745c62b8af4e10e46229e38fb71b2eb893c3a7d5 Mon Sep 17 00:00:00 2001 From: John Phan Date: Mon, 2 Dec 2024 08:28:52 -0800 Subject: [PATCH 6/6] Updated MolecularAnalysisRunItem foreign key name --- .../db/changelog/migrations/54-Add_metagenomics_tables.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3c31367e..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 @@ -54,7 +54,7 @@ references="pcr_batch_item(id)" /> -