Skip to content

Commit

Permalink
Merge pull request #248 from AAFC-BICoE/35276_add_metagenomic_workflo…
Browse files Browse the repository at this point in the history
…w_resource

35276 add metagenomic workflow resource
  • Loading branch information
brandonandre authored Dec 4, 2024
2 parents 16ad68a + eb2ac0a commit bae372f
Show file tree
Hide file tree
Showing 18 changed files with 676 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/main/java/ca/gc/aafc/seqdb/api/dto/MetagenomicsBatchDto.java
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;

}
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 src/main/java/ca/gc/aafc/seqdb/api/entities/MetagenomicsBatch.java
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;

}
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();
}

}
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);
}
}
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);
}
}
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());
}

}

Loading

0 comments on commit bae372f

Please sign in to comment.