-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #252 from AAFC-BICoE/35277_add_quality_control_sample
35277 add quality control sample
- Loading branch information
Showing
18 changed files
with
414 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/ca/gc/aafc/seqdb/api/dto/QualityControlDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package ca.gc.aafc.seqdb.api.dto; | ||
|
||
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; | ||
|
||
import org.javers.core.metamodel.annotation.Id; | ||
import org.javers.core.metamodel.annotation.PropertyName; | ||
import org.javers.core.metamodel.annotation.TypeName; | ||
|
||
import ca.gc.aafc.dina.dto.RelatedEntity; | ||
import ca.gc.aafc.seqdb.api.entities.QualityControl; | ||
|
||
@Builder | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@JsonApiResource(type = QualityControlDto.TYPENAME) | ||
@TypeName(QualityControlDto.TYPENAME) | ||
@RelatedEntity(QualityControl.class) | ||
public class QualityControlDto { | ||
|
||
public static final String TYPENAME = "quality-control"; | ||
|
||
@JsonApiId | ||
@Id | ||
@PropertyName("id") | ||
private UUID uuid; | ||
|
||
private String createdBy; | ||
private OffsetDateTime createdOn; | ||
|
||
private String group; | ||
|
||
private String name; | ||
|
||
private String qcType; | ||
|
||
@JsonApiRelation | ||
private MolecularAnalysisRunItemDto molecularAnalysisRunItem; | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/ca/gc/aafc/seqdb/api/entities/QualityControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ca.gc.aafc.seqdb.api.entities; | ||
|
||
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; | ||
|
||
import org.hibernate.annotations.Generated; | ||
import org.hibernate.annotations.GenerationTime; | ||
import org.hibernate.annotations.NaturalId; | ||
|
||
import ca.gc.aafc.dina.entity.DinaEntity; | ||
|
||
@Getter | ||
@Entity | ||
@Builder | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "quality_control") | ||
public class QualityControl 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; | ||
|
||
@NotBlank | ||
@Size(max = 50) | ||
@Column(name = "qc_type") | ||
private String qcType; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "molecular_analysis_run_item_id") | ||
private MolecularAnalysisRunItem molecularAnalysisRunItem; | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/ca/gc/aafc/seqdb/api/repository/QualityControlRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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.QualityControlDto; | ||
import ca.gc.aafc.seqdb.api.entities.QualityControl; | ||
import ca.gc.aafc.seqdb.api.service.QualityControlService; | ||
|
||
import java.util.Optional; | ||
import lombok.NonNull; | ||
|
||
@Repository | ||
public class QualityControlRepository extends DinaRepository<QualityControlDto, QualityControl> { | ||
|
||
private Optional<DinaAuthenticatedUser> dinaAuthenticatedUser; | ||
|
||
public QualityControlRepository( | ||
@NonNull QualityControlService dinaService, | ||
DinaAuthorizationService groupAuthorizationService, | ||
@NonNull BuildProperties props, | ||
ExternalResourceProvider externalResourceProvider, | ||
Optional<DinaAuthenticatedUser> dinaAuthenticatedUser, | ||
ObjectMapper objMapper) { | ||
super( | ||
dinaService, | ||
groupAuthorizationService, | ||
Optional.empty(), | ||
new DinaMapper<>(QualityControlDto.class), | ||
QualityControlDto.class, | ||
QualityControl.class, | ||
null, | ||
externalResourceProvider, | ||
props, objMapper); | ||
|
||
this.dinaAuthenticatedUser = dinaAuthenticatedUser; | ||
} | ||
|
||
@Override | ||
public <S extends QualityControlDto> S create(S resource) { | ||
dinaAuthenticatedUser.ifPresent( | ||
authenticatedUser -> resource.setCreatedBy(authenticatedUser.getUsername())); | ||
return super.create(resource); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/ca/gc/aafc/seqdb/api/service/QualityControlService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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.QualityControl; | ||
import ca.gc.aafc.seqdb.api.validation.QualityControlVocabularyValidator; | ||
|
||
@Service | ||
public class QualityControlService extends DefaultDinaService<QualityControl> { | ||
|
||
private final QualityControlVocabularyValidator qualityControlVocabularyValidator; | ||
|
||
public QualityControlService( | ||
@NonNull BaseDAO baseDAO, | ||
QualityControlVocabularyValidator qualityControlVocabularyValidator, | ||
@NonNull SmartValidator sv) { | ||
super(baseDAO, sv); | ||
this.qualityControlVocabularyValidator = qualityControlVocabularyValidator; | ||
} | ||
|
||
@Override | ||
protected void preCreate(QualityControl entity) { | ||
entity.setUuid(UUIDHelper.generateUUIDv7()); | ||
} | ||
|
||
@Override | ||
public void validateBusinessRules(QualityControl entity) { | ||
applyBusinessRule(entity, qualityControlVocabularyValidator); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/ca/gc/aafc/seqdb/api/validation/QualityControlVocabularyValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ca.gc.aafc.seqdb.api.validation; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.Errors; | ||
|
||
import ca.gc.aafc.dina.vocabulary.VocabularyElementConfiguration; | ||
import ca.gc.aafc.seqdb.api.SequenceVocabularyConfiguration; | ||
import ca.gc.aafc.seqdb.api.entities.QualityControl; | ||
|
||
@Component | ||
public class QualityControlVocabularyValidator extends VocabularyBasedValidator<QualityControl> { | ||
|
||
private static final String QUALITY_CONTROL_FIELD_NAME = "qcType"; | ||
private final List<VocabularyElementConfiguration> qcTypeVocabulary; | ||
|
||
QualityControlVocabularyValidator(MessageSource messageSource, SequenceVocabularyConfiguration vocabularyConfiguration) { | ||
super(QualityControl.class, messageSource); | ||
qcTypeVocabulary = vocabularyConfiguration.getVocabularyByKey(SequenceVocabularyConfiguration.QUALITY_CONTROL_TYPE_VOCAB_KEY); | ||
} | ||
|
||
@Override | ||
public void validateTarget(QualityControl target, Errors errors) { | ||
if (StringUtils.isBlank(target.getQcType())) { | ||
return; | ||
} | ||
|
||
target.setQcType(validateAndStandardizeValueAgainstVocabulary(target.getQcType(), | ||
QUALITY_CONTROL_FIELD_NAME, qcTypeVocabulary, errors)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.