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..f398075c --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.java @@ -0,0 +1,53 @@ +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; +import io.crnk.core.resource.annotations.JsonApiRelation; +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; +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 PcrBatchItemDto pcrBatchItem; + + @ShallowReference + @JsonApiRelation + private MolecularAnalysisRunItemDto molecularAnalysisRunItem; + + @JsonApiRelation + private NgsIndexDto indexI5; + + @JsonApiRelation + private NgsIndexDto indexI7; + +} 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..f28fc972 --- /dev/null +++ b/src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.java @@ -0,0 +1,84 @@ +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 ca.gc.aafc.seqdb.api.entities.pcr.PcrBatchItem; + +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 = "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; + + @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/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..37c2be3f --- /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); + } +} 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/main/resources/db/changelog/db.changelog-master.xml b/src/main/resources/db/changelog/db.changelog-master.xml index 8d58c493..6256550b 100644 --- a/src/main/resources/db/changelog/db.changelog-master.xml +++ b/src/main/resources/db/changelog/db.changelog-master.xml @@ -58,7 +58,7 @@ - + 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..67d44fa1 --- /dev/null +++ b/src/main/resources/db/changelog/migrations/54-Add_metagenomics_tables.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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 92c6f46d..4166e806 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; @@ -42,6 +44,12 @@ public class SequenceModuleBaseIT extends BaseIntegrationTest { @Inject protected GenericMolecularAnalysisItemService genericMolecularAnalysisItemService; + @Inject + protected MetagenomicsBatchService metagenomicsBatchService; + + @Inject + protected MetagenomicsBatchItemService metagenomicsBatchItemService; + @Inject protected SequenceManagedAttributeService managedAttributeService; 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..26f6d6e5 --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchIT.java @@ -0,0 +1,76 @@ +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.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; + +import javax.inject.Inject; + +public class MetagenomicsBatchIT extends BaseRepositoryTestV2 { + + @Inject + private MetagenomicsBatchRepository metagenomicsBatchRepository; + + @Inject + private MetagenomicsBatchItemRepository metagenomicsBatchItemRepository; + + @Inject + private PcrBatchRepository pcrBatchRepository; + + @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()); + + PcrBatchDto pcrBatchDto = PcrBatchTestFixture.newPcrBatch(); + pcrBatchDto = pcrBatchRepository.create(pcrBatchDto); + + 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); + } +} 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..e4f4910e --- /dev/null +++ b/src/test/java/ca/gc/aafc/seqdb/api/testsupport/fixtures/MetagenomicsBatchItemTestFixture.java @@ -0,0 +1,19 @@ +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") + .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(); + } +} 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);