Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
cgendreau committed Aug 4, 2023
2 parents 5cc19a8 + 0c6b124 commit 3693de5
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 73 deletions.
10 changes: 6 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>ca.gc.aafc</groupId>
<artifactId>seqdb.api</artifactId>
<version>2.8.0</version>
<version>2.9.0</version>
<packaging>jar</packaging>

<name>seqdb-api</name>
Expand All @@ -21,21 +21,23 @@
<!-- Override SpringBoot version (3.6) to avoid NoClassDefFoundError: org/apache/maven/doxia/siterenderer/DocumentContent -->
<maven-site-plugin.version>3.7.1</maven-site-plugin.version>

<dependency.check.version>8.1.2</dependency.check.version>
<dependency.check.version>8.3.1</dependency.check.version>
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<maven-checkstyle-plugin.version>3.1.2</maven-checkstyle-plugin.version>
<checkstyle.version>9.3</checkstyle.version>
<asciidoctor-maven-plugin.version>2.1.0</asciidoctor-maven-plugin.version>
<dina-base-api.version>0.104</dina-base-api.version>
<dina-base-api.version>0.110</dina-base-api.version>
<postgresql.version>42.4.3</postgresql.version>
<snakeyaml.version>1.33</snakeyaml.version>
<spring-boot-maven-plugin.fork>false</spring-boot-maven-plugin.fork>

<spring-security.version>5.7.10</spring-security.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.11</version>
<version>2.7.13</version>
</parent>

<!-- temporary until we can migrate to a newer version of Crnk-->
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/ca/gc/aafc/seqdb/api/dto/LibraryPrepDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.time.OffsetDateTime;
import java.util.UUID;

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.libraryprep.LibraryPrep;
import io.crnk.core.resource.annotations.JsonApiId;
import io.crnk.core.resource.annotations.JsonApiRelation;
Expand Down Expand Up @@ -34,14 +36,16 @@ public class LibraryPrepDto {

@JsonApiRelation
private LibraryPrepBatchDto libraryPrepBatch;

@JsonApiRelation
private MolecularSampleDto molecularSample;

@JsonApiRelation
private NgsIndexDto indexI5;

@JsonApiRelation
private NgsIndexDto indexI7;

@JsonApiExternalRelation(type = "material-sample")
@JsonApiRelation
private ExternalRelationDto materialSample;


}
2 changes: 2 additions & 0 deletions src/main/java/ca/gc/aafc/seqdb/api/dto/SeqReactionDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public class SeqReactionDto {
private Integer wellColumn;
private String wellRow;

private int cellNumber;

}
5 changes: 5 additions & 0 deletions src/main/java/ca/gc/aafc/seqdb/api/entities/SeqReaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
Expand Down Expand Up @@ -82,4 +83,8 @@ public class SeqReaction implements DinaEntity {
@Pattern(regexp = "[a-zA-Z]")
@Column(name = "well_row")
private String wellRow;

// calculated field
@Transient
private int cellNumber;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.hibernate.annotations.NaturalId;

import ca.gc.aafc.dina.entity.DinaEntity;
import ca.gc.aafc.seqdb.api.entities.MolecularSample;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -67,9 +66,8 @@ public class LibraryPrep implements DinaEntity {
private LibraryPrepBatch libraryPrepBatch;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "sampleid")
private MolecularSample molecularSample;
@Column(name = "material_sample")
private UUID materialSample;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "Indexi5id")
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/ca/gc/aafc/seqdb/api/service/SeqReactionService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
package ca.gc.aafc.seqdb.api.service;

import ca.gc.aafc.dina.entity.StorageGridLayout;
import ca.gc.aafc.dina.jpa.BaseDAO;
import ca.gc.aafc.dina.jpa.PredicateSupplier;
import ca.gc.aafc.dina.service.DefaultDinaService;
import ca.gc.aafc.dina.translator.NumberLetterTranslator;
import ca.gc.aafc.seqdb.api.entities.SeqBatch;
import ca.gc.aafc.seqdb.api.entities.SeqReaction;
import ca.gc.aafc.seqdb.api.validation.SeqReactionValidator;

import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;
import lombok.NonNull;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.SmartValidator;

Expand All @@ -23,6 +36,35 @@ public SeqReactionService(
this.validator = validator;
}

@Override
public <T> List<T> findAll(@NonNull Class<T> entityClass, @NonNull PredicateSupplier<T> where,
BiFunction<CriteriaBuilder, Root<T>, List<Order>> orderBy,
int startIndex, int maxResult, @NonNull Set<String> includes,
@NonNull Set<String> relationships) {

List<T> itemsList = super.findAll(entityClass, where, orderBy, startIndex, maxResult, includes, relationships);
if(SeqReaction.class == entityClass) {
itemsList.forEach(t -> setCellNumber((SeqReaction) t));
}
return itemsList;
}

private void setCellNumber(SeqReaction item) {

SeqBatch batch = item.getSeqBatch();
if (batch == null || batch.getStorageRestriction() == null) {
return;
}

// We assume row and col are valid, so we only check for row presence
if (StringUtils.isBlank(item.getWellRow())) {
return;
}

StorageGridLayout restriction = batch.getStorageRestriction().getLayout();
item.setCellNumber(restriction.calculateCellNumber(NumberLetterTranslator.toNumber(item.getWellRow()), item.getWellColumn()));
}

@Override
protected void preCreate(SeqReaction entity) {
entity.setUuid(UUID.randomUUID());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@
<include file="db/changelog/migrations/37-Add_batchType_to_PCRBatch.xml"/>
<include file="db/changelog/migrations/38-Add_sequencingType_to_SeqBatch.xml"/>
<include file="db/changelog/migrations/39-Add_isCompleted_to_SeqBatch.xml"/>
<include file="db/changelog/migrations/40-Change_LibraryPrep_molecularSample_to_MaterialSample.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
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">

<changeSet id="40-Change_LibraryPrep_molecularSample_to_MaterialSample" context="schema-change" author="cgendreau">

<dropColumn tableName="librarypreps">
<column name="sampleid"/>
</dropColumn>

<addColumn tableName="librarypreps">
<column name="material_sample" type="uuid"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
package ca.gc.aafc.seqdb.api.repository;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.validation.ValidationException;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import ca.gc.aafc.seqdb.api.dto.LibraryPrepBatchDto;
import ca.gc.aafc.seqdb.api.dto.LibraryPrepDto;
import ca.gc.aafc.seqdb.api.dto.MolecularSampleDto;
import ca.gc.aafc.seqdb.api.entities.ContainerType;
import ca.gc.aafc.seqdb.api.entities.Product;
import ca.gc.aafc.seqdb.api.entities.MolecularSample;
import ca.gc.aafc.seqdb.api.entities.libraryprep.LibraryPrep;
import ca.gc.aafc.seqdb.api.testsupport.factories.ContainerTypeFactory;
import ca.gc.aafc.seqdb.api.testsupport.factories.LibraryPrepFactory;
import ca.gc.aafc.seqdb.api.testsupport.factories.ProductFactory;
import ca.gc.aafc.seqdb.api.testsupport.fixtures.LibraryPrepTestFixture;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import io.crnk.core.queryspec.QuerySpec;
import javax.inject.Inject;
import javax.validation.ValidationException;

public class LibraryPrepRepositoryIT extends BaseRepositoryTest {

private static final String TEST_QUALITY = "test quality";

private LibraryPrep testLibPrep;
private LibraryPrepBatchDto testBatchDto;
private List<MolecularSample> testSamples;

@Inject
private LibraryPrepBatchRepository libraryPrepBatchRepository;

@Inject
private LibraryPrepRepository libraryPrepRepository;

@Inject
private MolecularSampleRepository molecularSampleRepository;

private LibraryPrep createTestLibraryPrep() {

ContainerType testContainerType = ContainerTypeFactory.newContainerType()
Expand All @@ -53,14 +45,8 @@ private LibraryPrep createTestLibraryPrep() {
Product testProduct = ProductFactory.newProduct().build();
persist(testProduct);

MolecularSample testMolecularSample = new MolecularSample();
testMolecularSample.setName("test sample");

persist(testMolecularSample);

testLibPrep = LibraryPrepFactory.newLibraryPrep()
.quality(TEST_QUALITY)
.molecularSample(testMolecularSample)
.build();
testLibPrep.getLibraryPrepBatch().setContainerType(testContainerType);
persist(testLibPrep.getLibraryPrepBatch());
Expand All @@ -70,15 +56,7 @@ private LibraryPrep createTestLibraryPrep() {
// field for the test. This doesn't matter in prod.
entityManager.flush();
entityManager.refresh(testLibPrep.getLibraryPrepBatch());

testSamples = new ArrayList<>();
for (int i = 1; i <= 22; i++) {
MolecularSample sample = new MolecularSample();
sample.setName("sample " + i);
testSamples.add(sample);
persist(sample);
}


testBatchDto = libraryPrepBatchRepository.findOne(
testLibPrep.getLibraryPrepBatch().getUuid(),
new QuerySpec(LibraryPrepBatchDto.class)
Expand All @@ -105,23 +83,17 @@ public void findLibPrep_whenLibPrepExists_libPrepReturned() {

@Test
public void createLibPrep_onSuccess_libPrepCreated() {
MolecularSampleDto newSample = new MolecularSampleDto();
newSample.setName("new sample");
MolecularSampleDto newSampleCreated = molecularSampleRepository.create(newSample);

LibraryPrepDto newDto = new LibraryPrepDto();
newDto.setSize("test size");
newDto.setMolecularSample(newSampleCreated);

LibraryPrepDto newDto = LibraryPrepTestFixture.newLibraryPrep();
newDto.setLibraryPrepBatch(testBatchDto);
newDto.setGroup("dina");


LibraryPrepDto created = libraryPrepRepository.create(newDto);

assertNotNull(created.getUuid());
assertEquals("test size", created.getSize());
assertEquals(
newSampleCreated.getUuid(),
created.getMolecularSample().getUuid()
LibraryPrepTestFixture.MATERIAL_SAMPLE_UUID.toString(),
created.getMaterialSample().getId()
);
assertEquals(
testLibPrep.getLibraryPrepBatch().getUuid(),
Expand All @@ -131,29 +103,17 @@ public void createLibPrep_onSuccess_libPrepCreated() {

@Test
public void createLibPrep_whenCellsOverLap_setExistingCellCoordinatesToNull() {
LibraryPrepDto prep1 = new LibraryPrepDto();
LibraryPrepDto prep1 = LibraryPrepTestFixture.newLibraryPrep();
prep1.setWellRow("B");
prep1.setWellColumn(5);
prep1.setGroup("dina");
prep1.setMolecularSample(
molecularSampleRepository.findOne(
testSamples.get(0).getUuid(),
new QuerySpec(MolecularSampleDto.class)
)
);
prep1.setMaterialSample(LibraryPrepTestFixture.newMaterialSampleExternalRelationship());
prep1.setLibraryPrepBatch(testBatchDto);
LibraryPrepDto createdPrep1 = libraryPrepRepository.create(prep1);

LibraryPrepDto prep2 = new LibraryPrepDto();
LibraryPrepDto prep2 = LibraryPrepTestFixture.newLibraryPrep();
prep2.setWellRow("B");
prep2.setWellColumn(5);
prep2.setGroup("dina");
prep2.setMolecularSample(
molecularSampleRepository.findOne(
testSamples.get(1).getUuid(),
new QuerySpec(MolecularSampleDto.class)
)
);
prep2.setMaterialSample(LibraryPrepTestFixture.newMaterialSampleExternalRelationship());
prep2.setLibraryPrepBatch(testBatchDto);

LibraryPrepDto createdPrep2 = libraryPrepRepository.create(prep2);
Expand All @@ -177,7 +137,7 @@ public void updateLibPrep_whenWellRowLetterInvalid_throwValidationException() {
);
dto.setWellRow("!");
dto.setWellColumn(1);
ValidationException exception = assertThrows(
assertThrows(
ValidationException.class,
() -> libraryPrepRepository.save(dto)
);
Expand Down Expand Up @@ -209,7 +169,7 @@ public void updateLibPrep_whenColumnIs0_throwValidationException() {
);
dto.setWellRow("A");
dto.setWellColumn(0);
ValidationException exception = assertThrows(
assertThrows(
ValidationException.class,
() -> libraryPrepRepository.save(dto)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.gc.aafc.seqdb.api.testsupport.factories;

import java.util.List;
import java.util.UUID;
import java.util.function.BiFunction;

import ca.gc.aafc.seqdb.api.entities.libraryprep.LibraryPrep;
Expand All @@ -17,7 +18,7 @@ public static LibraryPrep.LibraryPrepBuilder newLibraryPrep() {
return LibraryPrep.builder()
.group("dina")
.libraryPrepBatch(LibraryPrepBatchFactory.newLibraryPrepBatch().build())
.molecularSample(MolecularSampleFactory.newMolecularSample().build());
.materialSample(UUID.randomUUID());
}

public static List<LibraryPrep> newListOf(int qty) {
Expand Down
Loading

0 comments on commit 3693de5

Please sign in to comment.