-
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 #248 from AAFC-BICoE/35276_add_metagenomic_workflo…
…w_resource 35276 add metagenomic workflow resource
- Loading branch information
Showing
18 changed files
with
676 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchDto.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,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; | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchItemDto.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.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; | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatch.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,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; | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatchItem.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,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(); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchItemRepository.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,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<MetagenomicsBatchItemDto, MetagenomicsBatchItem> { | ||
|
||
private Optional<DinaAuthenticatedUser> dinaAuthenticatedUser; | ||
|
||
public MetagenomicsBatchItemRepository( | ||
@NonNull MetagenomicsBatchItemService dinaService, | ||
DinaAuthorizationService groupAuthorizationService, | ||
@NonNull BuildProperties props, | ||
ExternalResourceProvider externalResourceProvider, | ||
Optional<DinaAuthenticatedUser> 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 extends MetagenomicsBatchItemDto> S create(S resource) { | ||
dinaAuthenticatedUser.ifPresent( | ||
authenticatedUser -> resource.setCreatedBy(authenticatedUser.getUsername())); | ||
return super.create(resource); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/ca/gc/aafc/seqdb/api/repository/MetagenomicsBatchRepository.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,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<MetagenomicsBatchDto, MetagenomicsBatch> { | ||
|
||
private Optional<DinaAuthenticatedUser> dinaAuthenticatedUser; | ||
|
||
public MetagenomicsBatchRepository( | ||
@NonNull MetagenomicsBatchService dinaService, | ||
DinaAuthorizationService groupAuthorizationService, | ||
@NonNull BuildProperties props, | ||
ExternalResourceProvider externalResourceProvider, | ||
Optional<DinaAuthenticatedUser> 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 extends MetagenomicsBatchDto> S create(S resource) { | ||
dinaAuthenticatedUser.ifPresent( | ||
authenticatedUser -> resource.setCreatedBy(authenticatedUser.getUsername())); | ||
return super.create(resource); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/ca/gc/aafc/seqdb/api/service/MetagenomicsBatchItemService.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,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<MetagenomicsBatchItem> { | ||
|
||
public MetagenomicsBatchItemService( | ||
@NonNull BaseDAO baseDAO, @NonNull SmartValidator sv) { | ||
super(baseDAO, sv); | ||
} | ||
|
||
@Override | ||
protected void preCreate(MetagenomicsBatchItem entity) { | ||
entity.setUuid(UUIDHelper.generateUUIDv7()); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.