Skip to content

Commit

Permalink
Merge pull request #206 from AAFC-BICoE/29599_Add_coordinates_to_seq_…
Browse files Browse the repository at this point in the history
…reaction

29599 Add coordinates to seq reaction
  • Loading branch information
brandonandre authored Jan 4, 2023
2 parents 2393f58 + 42d1a5a commit 9342a30
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
3 changes: 3 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 @@ -44,4 +44,7 @@ public class SeqReactionDto {
@JsonApiRelation
private PcrPrimerDto seqPrimer;

private Integer wellColumn;
private String wellRow;

}
13 changes: 12 additions & 1 deletion src/main/java/ca/gc/aafc/seqdb/api/entities/SeqReaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import ca.gc.aafc.seqdb.api.entities.pcr.PcrBatchItem;
import org.hibernate.annotations.Generated;
Expand Down Expand Up @@ -70,5 +73,13 @@ public class SeqReaction implements DinaEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seq_primer_id")
private PcrPrimer seqPrimer;


@Min(value = 1)
@Max(value = 255)
@Column(name = "well_column")
private Integer wellColumn;

@Pattern(regexp = "[a-zA-Z]")
@Column(name = "well_row")
private String wellRow;
}
10 changes: 10 additions & 0 deletions src/main/java/ca/gc/aafc/seqdb/api/service/SeqReactionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ca.gc.aafc.dina.jpa.BaseDAO;
import ca.gc.aafc.dina.service.DefaultDinaService;
import ca.gc.aafc.seqdb.api.entities.SeqReaction;
import ca.gc.aafc.seqdb.api.validation.SeqReactionValidator;
import lombok.NonNull;
import org.springframework.stereotype.Service;
import org.springframework.validation.SmartValidator;
Expand All @@ -12,15 +13,24 @@
@Service
public class SeqReactionService extends DefaultDinaService<SeqReaction> {

private final SeqReactionValidator validator;

public SeqReactionService(
@NonNull BaseDAO baseDAO,
SeqReactionValidator validator,
@NonNull SmartValidator sv) {
super(baseDAO, sv);
this.validator = validator;
}

@Override
protected void preCreate(SeqReaction entity) {
entity.setUuid(UUID.randomUUID());
}

@Override
public void validateBusinessRules(SeqReaction entity) {
applyBusinessRule(entity, validator);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ca.gc.aafc.seqdb.api.validation;

import ca.gc.aafc.seqdb.api.entities.SeqReaction;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;

@Component
public class SeqReactionValidator extends AbstractLocationValidator {

public SeqReactionValidator(MessageSource messageSource) {
super(messageSource);
}

@Override
public boolean supports(Class<?> clazz) {
return SeqReaction.class.isAssignableFrom(clazz);
}

@Override
public void validate(Object target, Errors errors) {
if (!supports(target.getClass())) {
throw new IllegalArgumentException("SeqReactionValidator not supported for class " + target.getClass());
}
SeqReaction seqReaction = (SeqReaction) target;
// make sure we have a location to validate
if (StringUtils.isBlank(seqReaction.getWellRow()) && seqReaction.getWellColumn() == null) {
return;
}
checkRowAndColumn(seqReaction.getWellRow(), seqReaction.getWellColumn(), errors);
}

}
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 @@ -37,4 +37,5 @@
<include file="db/changelog/migrations/30-Allow_storage_unit_type_on_pcrbatch.xml"/>
<include file="db/changelog/migrations/31-Add_reaction_date_to_seqbatch.xml"/>
<include file="db/changelog/migrations/32-Add_sequencing_facility.xml"/>
<include file="db/changelog/migrations/33-Add_well_coordinates_SeqReaction.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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="33-Add_well_coordinates_SeqReaction" context="schema-change" author="cgendreau">
<addColumn tableName="seq_reaction">
<column name="well_column" type="INTEGER"/>
<column name="well_row" type="VARCHAR(2)"/>
</addColumn>
<sql>
ALTER TABLE seq_reaction ADD CONSTRAINT well_column_seqreaction_check CHECK (well_column &gt;=1 AND well_column &lt;= 255)
</sql>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public static SeqReactionDto newSeqReaction() {
SeqReactionDto seqReactionDto = new SeqReactionDto();
seqReactionDto.setGroup(GROUP);
seqReactionDto.setCreatedBy(CREATED_BY);
seqReactionDto.setWellRow("B");
seqReactionDto.setWellColumn(8);
return seqReactionDto;
}

Expand Down

0 comments on commit 9342a30

Please sign in to comment.