From b80c7554649a00e20d48b53fe67ca225a3d04295 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Fri, 22 Mar 2024 17:59:17 +0100 Subject: [PATCH 1/5] Added a meta-data table / entity - made a one-to-one-relationship between the levelOneEntity and the MetaDataEntity - set seqcol digest & naming_convention as the primary key of the meta-data table --- .../controller/admin/AdminController.java | 3 + .../eva/evaseqcol/entities/SeqColEntity.java | 2 - .../entities/SeqColLevelOneEntity.java | 22 +++--- .../entities/SeqColLevelTwoEntity.java | 5 -- .../evaseqcol/entities/SeqColMetadata.java | 67 +++++++++++++++++++ .../evaseqcol/entities/SeqColMetadataId.java | 22 ++++++ .../DuplicateSeqColWithDifferentMetadata.java | 8 +++ .../evaseqcol/repo/MetadataRepository.java | 15 +++++ .../repo/SeqColLevelOneRepository.java | 1 + .../evaseqcol/service/MetadataService.java | 35 ++++++++++ .../service/SeqColLevelOneService.java | 17 +++-- .../eva/evaseqcol/service/SeqColService.java | 11 ++- .../ebi/eva/evaseqcol/io/SeqColGenerator.java | 13 ++-- 13 files changed, 195 insertions(+), 26 deletions(-) create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/service/MetadataService.java diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java index 78e5ecf..6638b60 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java @@ -17,6 +17,7 @@ import uk.ac.ebi.eva.evaseqcol.exception.AssemblyAlreadyIngestedException; import uk.ac.ebi.eva.evaseqcol.exception.AssemblyNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException; +import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColWithDifferentMetadata; import uk.ac.ebi.eva.evaseqcol.exception.IncorrectAccessionException; import uk.ac.ebi.eva.evaseqcol.model.IngestionResultEntity; import uk.ac.ebi.eva.evaseqcol.service.SeqColService; @@ -71,6 +72,8 @@ public ResponseEntity fetchAndInsertSeqColByAssemblyAccession( return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (DuplicateSeqColException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT); + } catch (DuplicateSeqColWithDifferentMetadata e) { + return new ResponseEntity<>(e.getMessage(), HttpStatus.CREATED); // TODO: review this response } catch (AssemblyNotFoundException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND); } catch (AssemblyAlreadyIngestedException e) { diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColEntity.java index 05da0ca..585198a 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColEntity.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColEntity.java @@ -17,8 +17,6 @@ public abstract class SeqColEntity { protected String digest; // The level 0 digest - protected NamingConvention namingConvention; - public enum NamingConvention { ENA, GENBANK, UCSC, TEST diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java index dd47949..cfdc145 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java @@ -7,6 +7,7 @@ import uk.ac.ebi.eva.evaseqcol.utils.JSONLevelOne; import javax.persistence.Basic; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -14,13 +15,15 @@ import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.OneToOne; import javax.persistence.Table; @Entity @NoArgsConstructor @Data @Table(name = "sequence_collections_L1") -@IdClass(SeqColId.class) public class SeqColLevelOneEntity extends SeqColEntity{ @Id @@ -32,15 +35,16 @@ public class SeqColLevelOneEntity extends SeqColEntity{ @Basic(fetch = FetchType.LAZY) private JSONLevelOne seqColLevel1Object; - @Id - @Column(nullable = false) - @Enumerated(EnumType.STRING) - protected NamingConvention namingConvention; - - public SeqColLevelOneEntity(String digest, NamingConvention namingConvention, JSONLevelOne jsonLevelOne){ - super(digest, namingConvention); + @OneToOne(cascade = CascadeType.ALL) + @JoinColumns({ + @JoinColumn(name = "seqcol_digest", referencedColumnName = "seqcol_digest"), + @JoinColumn(name = "source_id", referencedColumnName = "source_identifier") + }) + private SeqColMetadata metadata; + public SeqColLevelOneEntity(String digest, JSONLevelOne jsonLevelOne, SeqColMetadata metadata){ + super(digest); this.seqColLevel1Object = jsonLevelOne; - this.namingConvention = namingConvention; + this.metadata = metadata; } @Override diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelTwoEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelTwoEntity.java index e707ae7..a7bea68 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelTwoEntity.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelTwoEntity.java @@ -24,9 +24,4 @@ public SeqColLevelTwoEntity setDigest(String digest) { this.digest = digest; return this; } - - public SeqColLevelTwoEntity setNamingConvention(NamingConvention convention) { - this.namingConvention = convention; - return this; - } } diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java new file mode 100644 index 0000000..b7a7ae6 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java @@ -0,0 +1,67 @@ +package uk.ac.ebi.eva.evaseqcol.entities; + +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import java.util.Date; + +@Entity +@IdClass(SeqColMetadataId.class) +@Table(name = "seqcol_md") +@Data +public class SeqColMetadata { + + @Id + @Column(name = "seqcol_digest") + private String seqColDigest; + + @Id + @Enumerated(EnumType.STRING) + @Column(name = "source_identifier") + private SourceIdentifier sourceIdentifier; + + private String sourceUrl; + + @Enumerated(EnumType.STRING) + private SeqColEntity.NamingConvention namingConvention; + + @Column(insertable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) + private Date timestamp; + + @OneToOne(mappedBy = "metadata") + private SeqColLevelOneEntity seqColLevelOne; + + public enum SourceIdentifier { + Insdc + } + + public SeqColMetadata setSeqColDigest(String digest) { + this.seqColDigest = digest; + return this; + } + + public SeqColMetadata setSourceIdentifier(SourceIdentifier sourceIdentifier) { + this.sourceIdentifier = sourceIdentifier; + return this; + } + + public SeqColMetadata setSourceUrl(String sourceUrl) { + this.sourceUrl = sourceUrl; + return this; + } + + public SeqColMetadata setNamingConvention(SeqColEntity.NamingConvention namingConvention) { + this.namingConvention = namingConvention; + return this; + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java new file mode 100644 index 0000000..fcca9c9 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java @@ -0,0 +1,22 @@ +package uk.ac.ebi.eva.evaseqcol.entities; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import javax.persistence.Embeddable; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +@EqualsAndHashCode +@Embeddable +@NoArgsConstructor +@AllArgsConstructor +public class SeqColMetadataId implements Serializable { + + @NotNull + private String seqColDigest; + @NotNull + private SeqColMetadata.SourceIdentifier sourceIdentifier; // Eg: INSDC, UCSC, GENBANK, etc.. + +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java new file mode 100644 index 0000000..2a7e0e0 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java @@ -0,0 +1,8 @@ +package uk.ac.ebi.eva.evaseqcol.exception; + +public class DuplicateSeqColWithDifferentMetadata extends RuntimeException{ + + public DuplicateSeqColWithDifferentMetadata(String digest) { + super("A similar seqCol already exists with digest " + digest + " but with different metadata"); + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java new file mode 100644 index 0000000..8a2d791 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java @@ -0,0 +1,15 @@ +package uk.ac.ebi.eva.evaseqcol.repo; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadata; +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataId; + +import java.util.List; + +@Repository +public interface MetadataRepository extends JpaRepository { + + List findAllBySeqColDigest(String digest); +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java index 27ff575..58972b3 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java @@ -14,4 +14,5 @@ public interface SeqColLevelOneRepository extends JpaRepository addMetadata(SeqColMetadata metadata) { + if (repository.existsById(new SeqColMetadataId(metadata.getSeqColDigest(), metadata.getSourceIdentifier()))){ + return Optional.empty(); + } + return Optional.of( + repository.save(metadata) + ); + } + + /** + * Return the list of all metadata entries for the seqCol object with the given digest*/ + public Optional> getAllMetadataForSeqColByDigest(String seqColDigest) { + return Optional.of( + repository.findAllBySeqColDigest(seqColDigest) + ); + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java index 2810409..12adad3 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java @@ -8,6 +8,7 @@ import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity; import uk.ac.ebi.eva.evaseqcol.digests.DigestCalculator; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity; +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadata; import uk.ac.ebi.eva.evaseqcol.repo.SeqColLevelOneRepository; import uk.ac.ebi.eva.evaseqcol.utils.JSONExtData; import uk.ac.ebi.eva.evaseqcol.utils.JSONIntegerListExtData; @@ -32,8 +33,12 @@ public class SeqColLevelOneService { * Add a new Level 1 sequence collection object and save it to the * database*/ public Optional addSequenceCollectionL1(SeqColLevelOneEntity seqColLevelOne){ - SeqColLevelOneEntity seqCol = repository.save(seqColLevelOne); - return Optional.of(seqCol); + if (repository.existsById(seqColLevelOne.getDigest())) { + return Optional.empty(); + } + return Optional.of( + repository.save(seqColLevelOne) + ); } public Optional getSeqColLevelOneByDigest(String digest){ @@ -62,12 +67,15 @@ public List getAllSeqColLevelOneObjects(){ /** * Construct a seqCol level 1 entity out of three seqCol level 2 entities that - * hold names, lengths and sequences objects*/ + * hold names, lengths and sequences objects + * TODO: Change the signature of this method and make it accept metadata object instead of namingconvention*/ public SeqColLevelOneEntity constructSeqColLevelOne(List>> stringListExtendedDataEntities, List>> integerListExtendedDataEntities, SeqColEntity.NamingConvention convention) throws IOException { SeqColLevelOneEntity levelOneEntity = new SeqColLevelOneEntity(); JSONLevelOne jsonLevelOne = new JSONLevelOne(); + SeqColMetadata metadata = new SeqColMetadata().setNamingConvention(convention) + .setSourceIdentifier(SeqColMetadata.SourceIdentifier.Insdc); // TODO: this should be specified by the method parameter // Looping over List types for (SeqColExtendedDataEntity> dataEntity: stringListExtendedDataEntities) { @@ -99,7 +107,8 @@ public SeqColLevelOneEntity constructSeqColLevelOne(List addFullSequenceCollection( ) { long numSeqCols = levelOneService.countSeqColLevelOneEntitiesByDigest(levelOneEntity.getDigest()); if (numSeqCols > 0) { + // Checking for possibly different metadata + if (metadataService.addMetadata(levelOneEntity.getMetadata()).isPresent()) { + logger.warn("SeqCol with digest " + levelOneEntity.getDigest() + " already exists but with different metadata!"); + throw new DuplicateSeqColWithDifferentMetadata(levelOneEntity.getDigest()); + } logger.warn("SeqCol with digest " + levelOneEntity.getDigest() + " already exists !"); throw new DuplicateSeqColException(levelOneEntity.getDigest()); } else { diff --git a/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java b/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java index e4ccd41..75329bf 100644 --- a/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java +++ b/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java @@ -5,6 +5,7 @@ import uk.ac.ebi.eva.evaseqcol.entities.SeqColEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity; +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadata; import uk.ac.ebi.eva.evaseqcol.utils.JSONLevelOne; import java.util.Arrays; @@ -16,24 +17,27 @@ public class SeqColGenerator { /** * Return an example (might not be real) of a seqCol object level 1 - * The naming convention is set to GENBANK as a random choice*/ + * The naming convention is set to GENBANK as a random choice + * and source identifier is set Insdc*/ public SeqColLevelOneEntity generateLevelOneEntity() { SeqColLevelOneEntity levelOneEntity = new SeqColLevelOneEntity(); JSONLevelOne jsonLevelOne = new JSONLevelOne(); + SeqColMetadata metadata = new SeqColMetadata() + .setNamingConvention(SeqColEntity.NamingConvention.GENBANK) + .setSeqColDigest("PgQMkKm2A8I9GVW7hJWcJ3erxuaMbHpD") + .setSourceIdentifier(SeqColMetadata.SourceIdentifier.Insdc); jsonLevelOne.setNames("mfxUkK3J5y7BGVW7hJWcJ3erxuaMX6xm"); jsonLevelOne.setSequences("dda3Kzi1Wkm2A8I99WietU1R8J4PL-D6"); jsonLevelOne.setLengths("Ms_ixPgQMJaM54dVntLWeovXSO7ljvZh"); jsonLevelOne.setMd5DigestsOfSequences("_6iaYtcWw4TZaowlL7_64Wu9mbHpDUw4"); jsonLevelOne.setSortedNameLengthPairs("QFuKs5Hh8uQwwUtnRxIf8W3zeJoFOp8Z"); levelOneEntity.setSeqColLevel1Object(jsonLevelOne); - levelOneEntity.setDigest("3mTg0tAA3PS-R1TzelLVWJ2ilUzoWfVq"); - levelOneEntity.setNamingConvention(SeqColEntity.NamingConvention.GENBANK); + levelOneEntity.setMetadata(metadata); return levelOneEntity; } /** * Return an example (might not be real) of a seqCol object level 2 - * The naming convention is set to GENBANK as a random choice * */ public SeqColLevelTwoEntity generateLevelTwoEntity() { SeqColLevelTwoEntity levelTwoEntity = new SeqColLevelTwoEntity(); @@ -128,7 +132,6 @@ public SeqColLevelTwoEntity generateLevelTwoEntity() { "YfHZgnpuJm4SN3RN4XL1VWWWZwTXtqw5" )); levelTwoEntity.setDigest("3mTg0tAA3PS-R1TzelLVWJ2ilUzoWfVq"); - levelTwoEntity.setNamingConvention(SeqColEntity.NamingConvention.GENBANK); return levelTwoEntity; } } From ecff1da16ca061ba3ddcf2454f54456ee4b85d66 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Fri, 12 Apr 2024 21:42:30 +0100 Subject: [PATCH 2/5] developed one to many approach for the seqcol metadata --- .../controller/admin/AdminController.java | 4 - .../controller/seqcol/MetadataController.java | 37 ++++++++ .../eva/evaseqcol/dto/SeqColMetadataDTO.java | 30 +++++++ .../entities/SeqColLevelOneEntity.java | 34 ++++---- .../evaseqcol/entities/SeqColMetadata.java | 67 --------------- .../entities/SeqColMetadataEntity.java | 86 +++++++++++++++++++ .../evaseqcol/entities/SeqColMetadataId.java | 22 ----- .../DuplicateSeqColWithDifferentMetadata.java | 8 -- .../evaseqcol/repo/MetadataRepository.java | 10 ++- .../repo/SeqColLevelOneRepository.java | 5 +- .../evaseqcol/service/MetadataService.java | 33 ++++--- .../service/SeqColLevelOneService.java | 34 ++++---- .../eva/evaseqcol/service/SeqColService.java | 23 ++--- .../ebi/eva/evaseqcol/io/SeqColGenerator.java | 13 +-- .../ac/ebi/eva/evaseqcol/io/SeqColWriter.java | 6 +- .../service/SeqColLevelOneServiceTest.java | 8 +- 16 files changed, 244 insertions(+), 176 deletions(-) create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/controller/seqcol/MetadataController.java create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/dto/SeqColMetadataDTO.java delete mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java create mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataEntity.java delete mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java delete mode 100644 src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java index 6638b60..10f7f91 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/admin/AdminController.java @@ -17,13 +17,11 @@ import uk.ac.ebi.eva.evaseqcol.exception.AssemblyAlreadyIngestedException; import uk.ac.ebi.eva.evaseqcol.exception.AssemblyNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException; -import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColWithDifferentMetadata; import uk.ac.ebi.eva.evaseqcol.exception.IncorrectAccessionException; import uk.ac.ebi.eva.evaseqcol.model.IngestionResultEntity; import uk.ac.ebi.eva.evaseqcol.service.SeqColService; import java.io.IOException; -import java.util.List; @RequestMapping("/admin") @RestController @@ -72,8 +70,6 @@ public ResponseEntity fetchAndInsertSeqColByAssemblyAccession( return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } catch (DuplicateSeqColException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT); - } catch (DuplicateSeqColWithDifferentMetadata e) { - return new ResponseEntity<>(e.getMessage(), HttpStatus.CREATED); // TODO: review this response } catch (AssemblyNotFoundException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND); } catch (AssemblyAlreadyIngestedException e) { diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/seqcol/MetadataController.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/seqcol/MetadataController.java new file mode 100644 index 0000000..8df38e4 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/controller/seqcol/MetadataController.java @@ -0,0 +1,37 @@ +package uk.ac.ebi.eva.evaseqcol.controller.seqcol; + +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import uk.ac.ebi.eva.evaseqcol.dto.SeqColMetadataDTO; +import uk.ac.ebi.eva.evaseqcol.service.MetadataService; + +import java.util.List; +import java.util.stream.Collectors; + +@RestController +@RequestMapping("/metadata/") +@Tag(name = "Seqcol metadata") +public class MetadataController { + + private final MetadataService metadataService; + + public MetadataController(MetadataService metadataService) { + this.metadataService = metadataService; + } + + @GetMapping(value = "/{digest}") + public ResponseEntity> getSeqColMetadataByDigest(@PathVariable String digest) { + List metadataList = metadataService.getMetadataBySeqColDigest(digest).stream() + .map(SeqColMetadataDTO::toMetadataDTO) + .collect(Collectors.toList()); + if (metadataList.isEmpty()) { + return ResponseEntity.notFound().build(); + } + return ResponseEntity.ok(metadataList); + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/dto/SeqColMetadataDTO.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/dto/SeqColMetadataDTO.java new file mode 100644 index 0000000..97b74fe --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/dto/SeqColMetadataDTO.java @@ -0,0 +1,30 @@ +package uk.ac.ebi.eva.evaseqcol.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import uk.ac.ebi.eva.evaseqcol.entities.SeqColEntity; +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataEntity; + +import java.util.Date; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SeqColMetadataDTO { + + private String sourceId; + private String sourceUrl; + private SeqColEntity.NamingConvention namingConvention; + private Date timestamp; + + public static SeqColMetadataDTO toMetadataDTO(SeqColMetadataEntity metadataEntity) { + return new SeqColMetadataDTO( + metadataEntity.getSourceIdentifier(), + metadataEntity.getSourceUrl(), + metadataEntity.getNamingConvention(), + metadataEntity.getTimestamp() + ); + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java index cfdc145..12e85e1 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColLevelOneEntity.java @@ -1,7 +1,6 @@ package uk.ac.ebi.eva.evaseqcol.entities; import lombok.Data; -import lombok.NoArgsConstructor; import org.hibernate.annotations.Type; import uk.ac.ebi.eva.evaseqcol.utils.JSONLevelOne; @@ -10,18 +9,14 @@ import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.FetchType; import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.OneToOne; +import javax.persistence.OneToMany; import javax.persistence.Table; +import java.util.ArrayList; +import java.util.List; @Entity -@NoArgsConstructor @Data @Table(name = "sequence_collections_L1") public class SeqColLevelOneEntity extends SeqColEntity{ @@ -35,18 +30,27 @@ public class SeqColLevelOneEntity extends SeqColEntity{ @Basic(fetch = FetchType.LAZY) private JSONLevelOne seqColLevel1Object; - @OneToOne(cascade = CascadeType.ALL) - @JoinColumns({ - @JoinColumn(name = "seqcol_digest", referencedColumnName = "seqcol_digest"), - @JoinColumn(name = "source_id", referencedColumnName = "source_identifier") - }) - private SeqColMetadata metadata; - public SeqColLevelOneEntity(String digest, JSONLevelOne jsonLevelOne, SeqColMetadata metadata){ + @OneToMany(mappedBy = "seqColLevelOne", cascade = CascadeType.ALL) + private List metadata; + + public SeqColLevelOneEntity() { + this.metadata = new ArrayList<>(); + } + + public SeqColLevelOneEntity(String digest, JSONLevelOne jsonLevelOne, List metadata){ super(digest); this.seqColLevel1Object = jsonLevelOne; this.metadata = metadata; } + public void addMetadata(SeqColMetadataEntity metadata){ + this.metadata.add(metadata); + } + + public void addAllMetadata(List metadata){ + this.metadata.addAll(metadata); + } + @Override public String toString() { return "{\n" + diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java deleted file mode 100644 index b7a7ae6..0000000 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.java +++ /dev/null @@ -1,67 +0,0 @@ -package uk.ac.ebi.eva.evaseqcol.entities; - -import lombok.Data; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.OneToOne; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import java.util.Date; - -@Entity -@IdClass(SeqColMetadataId.class) -@Table(name = "seqcol_md") -@Data -public class SeqColMetadata { - - @Id - @Column(name = "seqcol_digest") - private String seqColDigest; - - @Id - @Enumerated(EnumType.STRING) - @Column(name = "source_identifier") - private SourceIdentifier sourceIdentifier; - - private String sourceUrl; - - @Enumerated(EnumType.STRING) - private SeqColEntity.NamingConvention namingConvention; - - @Column(insertable = false, updatable = false) - @Temporal(TemporalType.TIMESTAMP) - private Date timestamp; - - @OneToOne(mappedBy = "metadata") - private SeqColLevelOneEntity seqColLevelOne; - - public enum SourceIdentifier { - Insdc - } - - public SeqColMetadata setSeqColDigest(String digest) { - this.seqColDigest = digest; - return this; - } - - public SeqColMetadata setSourceIdentifier(SourceIdentifier sourceIdentifier) { - this.sourceIdentifier = sourceIdentifier; - return this; - } - - public SeqColMetadata setSourceUrl(String sourceUrl) { - this.sourceUrl = sourceUrl; - return this; - } - - public SeqColMetadata setNamingConvention(SeqColEntity.NamingConvention namingConvention) { - this.namingConvention = namingConvention; - return this; - } -} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataEntity.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataEntity.java new file mode 100644 index 0000000..24dfdb3 --- /dev/null +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataEntity.java @@ -0,0 +1,86 @@ +package uk.ac.ebi.eva.evaseqcol.entities; + +import lombok.Data; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +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.persistence.Temporal; +import javax.persistence.TemporalType; +import java.sql.Timestamp; +import java.util.Date; +import java.util.Objects; + +@Entity +@Table(name = "seqcol_md") +@Data +public class SeqColMetadataEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "md_id") + private Long mdId; + + @Column(name = "source_id") + private String sourceIdentifier; // Eg: INSDC Acession + + private String sourceUrl; + + @Enumerated(EnumType.STRING) + private SeqColEntity.NamingConvention namingConvention; + + @Column(updatable = false) + @Temporal(TemporalType.TIMESTAMP) + @CreationTimestamp + private Date timestamp; + + @ManyToOne(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "seqcol_digest") + @OnDelete(action = OnDeleteAction.CASCADE) + private SeqColLevelOneEntity seqColLevelOne; + + public SeqColMetadataEntity setTimestamp(Timestamp timestamp) { + this.timestamp = timestamp; + return this; + } + + public SeqColMetadataEntity setSourceIdentifier(String sourceIdentifier) { + this.sourceIdentifier = sourceIdentifier; + return this; + } + + public SeqColMetadataEntity setSourceUrl(String sourceUrl) { + this.sourceUrl = sourceUrl; + return this; + } + + public SeqColMetadataEntity setNamingConvention(SeqColEntity.NamingConvention namingConvention) { + this.namingConvention = namingConvention; + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SeqColMetadataEntity)) return false; + SeqColMetadataEntity that = (SeqColMetadataEntity) o; + return Objects.equals(sourceIdentifier, that.sourceIdentifier) && Objects.equals(sourceUrl, that.sourceUrl) + && namingConvention == that.namingConvention && Objects.equals(seqColLevelOne, that.seqColLevelOne); + } + + @Override + public int hashCode() { + return Objects.hash(sourceIdentifier, sourceUrl, namingConvention, seqColLevelOne); + } +} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java deleted file mode 100644 index fcca9c9..0000000 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.java +++ /dev/null @@ -1,22 +0,0 @@ -package uk.ac.ebi.eva.evaseqcol.entities; - -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -import javax.persistence.Embeddable; -import javax.validation.constraints.NotNull; -import java.io.Serializable; - -@EqualsAndHashCode -@Embeddable -@NoArgsConstructor -@AllArgsConstructor -public class SeqColMetadataId implements Serializable { - - @NotNull - private String seqColDigest; - @NotNull - private SeqColMetadata.SourceIdentifier sourceIdentifier; // Eg: INSDC, UCSC, GENBANK, etc.. - -} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java deleted file mode 100644 index 2a7e0e0..0000000 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.java +++ /dev/null @@ -1,8 +0,0 @@ -package uk.ac.ebi.eva.evaseqcol.exception; - -public class DuplicateSeqColWithDifferentMetadata extends RuntimeException{ - - public DuplicateSeqColWithDifferentMetadata(String digest) { - super("A similar seqCol already exists with digest " + digest + " but with different metadata"); - } -} diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java index 8a2d791..2002e9e 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.java @@ -1,15 +1,17 @@ package uk.ac.ebi.eva.evaseqcol.repo; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; -import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadata; -import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataId; +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataEntity; import java.util.List; @Repository -public interface MetadataRepository extends JpaRepository { +public interface MetadataRepository extends JpaRepository { + + @Query(value = "select source_id from seqcol_md",nativeQuery = true) + List findAllSourceIds(); - List findAllBySeqColDigest(String digest); } diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java index 58972b3..dc363bf 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/repo/SeqColLevelOneRepository.java @@ -5,10 +5,11 @@ import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity; +import java.util.Optional; + @Repository public interface SeqColLevelOneRepository extends JpaRepository { - SeqColLevelOneEntity findSeqColLevelOneEntityByDigest(String digest); - + Optional findSeqColLevelOneEntityByDigest(String digest); long countSeqColLevelOneEntitiesByDigest(String digest); void removeSeqColLevelOneEntityByDigest(String digest); diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/MetadataService.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/MetadataService.java index 6f87233..db670ef 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/MetadataService.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/MetadataService.java @@ -3,33 +3,32 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadata; -import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataId; +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataEntity; import uk.ac.ebi.eva.evaseqcol.repo.MetadataRepository; import java.util.List; -import java.util.Optional; +import java.util.stream.Collectors; + @Service public class MetadataService { + private final MetadataRepository metadataRepository; + @Autowired - private MetadataRepository repository; - - public Optional addMetadata(SeqColMetadata metadata) { - if (repository.existsById(new SeqColMetadataId(metadata.getSeqColDigest(), metadata.getSourceIdentifier()))){ - return Optional.empty(); - } - return Optional.of( - repository.save(metadata) - ); + public MetadataService(MetadataRepository metadataRepository) { + this.metadataRepository = metadataRepository; } + public List getMetadataBySeqColDigest(String seqColDigest) { + return metadataRepository.findAll().stream() + .filter(metadataEntity -> metadataEntity.getSeqColLevelOne().getDigest().equals(seqColDigest)) + .collect(Collectors.toList()); + } /** - * Return the list of all metadata entries for the seqCol object with the given digest*/ - public Optional> getAllMetadataForSeqColByDigest(String seqColDigest) { - return Optional.of( - repository.findAllBySeqColDigest(seqColDigest) - ); + * Return the list of all saved source identifiers. Eg: ["GCA_000146045.2", ...] + * */ + public List getAllSourceIds() { + return metadataRepository.findAllSourceIds(); } } diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java index 12adad3..009502f 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java @@ -2,13 +2,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import uk.ac.ebi.eva.evaseqcol.entities.SeqColEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColExtendedDataEntity; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity; import uk.ac.ebi.eva.evaseqcol.digests.DigestCalculator; import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity; -import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadata; +import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataEntity; import uk.ac.ebi.eva.evaseqcol.repo.SeqColLevelOneRepository; import uk.ac.ebi.eva.evaseqcol.utils.JSONExtData; import uk.ac.ebi.eva.evaseqcol.utils.JSONIntegerListExtData; @@ -16,7 +17,9 @@ import uk.ac.ebi.eva.evaseqcol.utils.JSONStringListExtData; import java.io.IOException; +import java.sql.Timestamp; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Optional; @@ -24,14 +27,19 @@ @Service public class SeqColLevelOneService { - @Autowired - private SeqColLevelOneRepository repository; + private final SeqColLevelOneRepository repository; private DigestCalculator digestCalculator = new DigestCalculator(); + @Autowired + public SeqColLevelOneService(SeqColLevelOneRepository repository) { + this.repository = repository; + } + /** * Add a new Level 1 sequence collection object and save it to the * database*/ + @Transactional public Optional addSequenceCollectionL1(SeqColLevelOneEntity seqColLevelOne){ if (repository.existsById(seqColLevelOne.getDigest())) { return Optional.empty(); @@ -42,12 +50,7 @@ public Optional addSequenceCollectionL1(SeqColLevelOneEnti } public Optional getSeqColLevelOneByDigest(String digest){ - SeqColLevelOneEntity seqColL11 = repository.findSeqColLevelOneEntityByDigest(digest); - if (seqColL11 != null) { - return Optional.of(seqColL11); - } else { - return Optional.empty(); - } + return repository.findSeqColLevelOneEntityByDigest(digest); } public void removeSeqColLevelOneByDigest(String digest) { @@ -71,11 +74,11 @@ public List getAllSeqColLevelOneObjects(){ * TODO: Change the signature of this method and make it accept metadata object instead of namingconvention*/ public SeqColLevelOneEntity constructSeqColLevelOne(List>> stringListExtendedDataEntities, List>> integerListExtendedDataEntities, - SeqColEntity.NamingConvention convention) throws IOException { + SeqColEntity.NamingConvention convention, String sourceId) throws IOException { SeqColLevelOneEntity levelOneEntity = new SeqColLevelOneEntity(); JSONLevelOne jsonLevelOne = new JSONLevelOne(); - SeqColMetadata metadata = new SeqColMetadata().setNamingConvention(convention) - .setSourceIdentifier(SeqColMetadata.SourceIdentifier.Insdc); // TODO: this should be specified by the method parameter + SeqColMetadataEntity metadata = new SeqColMetadataEntity().setNamingConvention(convention) + .setSourceIdentifier(sourceId); // TODO: this (metadata object) should be passed in the method parameter // Looping over List types for (SeqColExtendedDataEntity> dataEntity: stringListExtendedDataEntities) { @@ -107,15 +110,14 @@ public SeqColLevelOneEntity constructSeqColLevelOne(List> sequencesExtData = new JSONStringListExtData(levelTwoEntity.getSequences()); JSONExtData> lengthsExtData = new JSONIntegerListExtData(levelTwoEntity.getLengths()); @@ -160,7 +162,7 @@ public SeqColLevelOneEntity constructSeqColLevelOne( lengthsExtEntity ); - return constructSeqColLevelOne(stringListExtendedDataEntities,integerListExtendedDataEntities, convention); + return constructSeqColLevelOne(stringListExtendedDataEntities,integerListExtendedDataEntities, convention, sourceId); } /** diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java index c05e558..6b60b44 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java @@ -18,7 +18,6 @@ import uk.ac.ebi.eva.evaseqcol.exception.AssemblyNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.AttributeNotDefinedException; import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException; -import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColWithDifferentMetadata; import uk.ac.ebi.eva.evaseqcol.exception.SeqColNotFoundException; import uk.ac.ebi.eva.evaseqcol.exception.UnableToLoadServiceInfoException; import uk.ac.ebi.eva.evaseqcol.model.IngestionResultEntity; @@ -77,14 +76,10 @@ public Optional addFullSequenceCollection( ) { long numSeqCols = levelOneService.countSeqColLevelOneEntitiesByDigest(levelOneEntity.getDigest()); if (numSeqCols > 0) { - // Checking for possibly different metadata - if (metadataService.addMetadata(levelOneEntity.getMetadata()).isPresent()) { - logger.warn("SeqCol with digest " + levelOneEntity.getDigest() + " already exists but with different metadata!"); - throw new DuplicateSeqColWithDifferentMetadata(levelOneEntity.getDigest()); - } logger.warn("SeqCol with digest " + levelOneEntity.getDigest() + " already exists !"); throw new DuplicateSeqColException(levelOneEntity.getDigest()); - } else { + }else { + levelOneEntity.getMetadata().forEach(md -> md.setSeqColLevelOne(levelOneEntity)); SeqColLevelOneEntity levelOneEntity1 = levelOneService.addSequenceCollectionL1(levelOneEntity).get(); extendedDataService.addAll(seqColStringListExtDataEntities); extendedDataService.addAll(seqColIntegerListExtDataEntities); @@ -174,6 +169,13 @@ public IngestionResultEntity fetchAndInsertAllSeqColInFastaFile(String accession * assembly report. * Return the list of level 0 digests of the inserted seqcol objects*/ public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession(String assemblyAccession) throws IOException { + // Check for existing same source id + boolean sourceIdExists = metadataService.getAllSourceIds().stream() + .anyMatch(sourceId -> sourceId.equals(assemblyAccession)); + if (sourceIdExists) { + logger.warn("Seqcol objects for assembly" + assemblyAccession + " have been already ingested. Nothing to ingest !"); + throw new AssemblyAlreadyIngestedException(assemblyAccession); + } Optional> seqColDataMap = ncbiSeqColDataSource.getAllPossibleSeqColExtendedData(assemblyAccession); return createSeqColObjectsAndInsert(seqColDataMap, assemblyAccession); } @@ -215,9 +217,8 @@ public IngestionResultEntity createSeqColObjectsAndInsert(Optional seqColDigest = insertSeqColL1AndL2( // TODO: Check for possible self invocation problem levelOneEntity, seqColStringListExtDataEntities, seqColIntegerListExtDataEntities); @@ -236,7 +237,7 @@ public IngestionResultEntity createSeqColObjectsAndInsert(Optional>>) ucscExtendedDataMap.get("integerListExtDataList"); levelOneEntityUcsc = levelOneService.constructSeqColLevelOne( - extendedStringListDataEntitiesUcsc, extendedIntegerListDataEntitiesUcsc, SeqColEntity.NamingConvention.UCSC); + extendedStringListDataEntitiesUcsc, extendedIntegerListDataEntitiesUcsc, + SeqColEntity.NamingConvention.UCSC, GCA_ACCESSION); Optional resultDigestUcsc = seqColService.addFullSequenceCollection( levelOneEntityUcsc, extendedStringListDataEntitiesUcsc, extendedIntegerListDataEntitiesUcsc); if (resultDigestUcsc.isPresent()) { @@ -163,7 +164,8 @@ public void create() throws IOException { extendedIntegerListDataEntitiesGenbank = (List>>) genbankExtendedDataMap.get("integerListExtDataList"); levelOneEntityGenbank = levelOneService.constructSeqColLevelOne( - extendedStringListDataEntitiesGenbank, extendedIntegerListDataEntitiesGenbank, SeqColEntity.NamingConvention.GENBANK); + extendedStringListDataEntitiesGenbank, extendedIntegerListDataEntitiesGenbank, + SeqColEntity.NamingConvention.GENBANK, GCA_ACCESSION); Optional resultDigestGenbank = seqColService.addFullSequenceCollection( levelOneEntityGenbank, extendedStringListDataEntitiesGenbank, extendedIntegerListDataEntitiesGenbank); if (resultDigestGenbank.isPresent()) { diff --git a/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java b/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java index 8d0bd66..30248b0 100644 --- a/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java +++ b/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java @@ -33,6 +33,8 @@ @Testcontainers class SeqColLevelOneServiceTest { + private final String GCA_ACCESSION = "GCA_000146045.2"; + @Autowired private AssemblyDataGenerator assemblyDataGenerator; @@ -82,10 +84,10 @@ void constructSeqColL1Test() throws IOException { List>> integerListExtDataList = (List>>) extendedDataMapGenbank.get("integerListExtDataList"); SeqColLevelOneEntity levelOneEntity = levelOneService.constructSeqColLevelOne( - stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK); + stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK, GCA_ACCESSION); SeqColLevelTwoEntity levelTwoEntity = levelTwoService. constructSeqColL2(levelOneEntity.getDigest(), stringListExtDataList, integerListExtDataList); - SeqColLevelOneEntity constructedEntity = levelOneService.constructSeqColLevelOne(levelTwoEntity, SeqColEntity.NamingConvention.GENBANK); + SeqColLevelOneEntity constructedEntity = levelOneService.constructSeqColLevelOne(levelTwoEntity, SeqColEntity.NamingConvention.GENBANK, GCA_ACCESSION); assertNotNull(constructedEntity); assertNotNull(constructedEntity.getSeqColLevel1Object().getSequences()); } @@ -100,7 +102,7 @@ void addSequenceCollectionL1() throws IOException { List>> integerListExtDataList = (List>>) extendedDataMapGenbank.get("integerListExtDataList"); SeqColLevelOneEntity levelOneEntity = levelOneService.constructSeqColLevelOne( - stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK); + stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK, GCA_ACCESSION); Optional savedEntity = levelOneService.addSequenceCollectionL1(levelOneEntity); assertTrue(savedEntity.isPresent()); System.out.println(savedEntity.get()); From fc53f9f2c7d2e17e502053a0bbceab21387e71d2 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Fri, 12 Apr 2024 23:09:02 +0100 Subject: [PATCH 3/5] clean up unnecessary imports --- .../uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java | 2 -- src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java | 1 - 2 files changed, 3 deletions(-) diff --git a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java index 009502f..cf19923 100644 --- a/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java +++ b/src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneService.java @@ -17,9 +17,7 @@ import uk.ac.ebi.eva.evaseqcol.utils.JSONStringListExtData; import java.io.IOException; -import java.sql.Timestamp; import java.util.Arrays; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Optional; diff --git a/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java b/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java index 7e41805..6aadba7 100644 --- a/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java +++ b/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java @@ -8,7 +8,6 @@ import uk.ac.ebi.eva.evaseqcol.entities.SeqColMetadataEntity; import uk.ac.ebi.eva.evaseqcol.utils.JSONLevelOne; -import java.sql.Timestamp; import java.util.Arrays; /** From 87b9a634a9b832c50a6a0bf6d5bceb1037137bc3 Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Sat, 13 Apr 2024 11:58:59 +0100 Subject: [PATCH 4/5] update test with metadata setup --- .../ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java b/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java index 30248b0..3d06afa 100644 --- a/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java +++ b/src/test/java/uk/ac/ebi/eva/evaseqcol/service/SeqColLevelOneServiceTest.java @@ -103,6 +103,7 @@ void addSequenceCollectionL1() throws IOException { (List>>) extendedDataMapGenbank.get("integerListExtDataList"); SeqColLevelOneEntity levelOneEntity = levelOneService.constructSeqColLevelOne( stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK, GCA_ACCESSION); + levelOneEntity.getMetadata().forEach(md -> md.setSeqColLevelOne(levelOneEntity)); Optional savedEntity = levelOneService.addSequenceCollectionL1(levelOneEntity); assertTrue(savedEntity.isPresent()); System.out.println(savedEntity.get()); From 82274e14508c39548f46c5f84bdad7d286d08c3d Mon Sep 17 00:00:00 2001 From: waterflow80 Date: Sat, 20 Apr 2024 22:50:49 +0100 Subject: [PATCH 5/5] recoverd mistakenly deleted line --- src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java b/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java index 6aadba7..949184e 100644 --- a/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java +++ b/src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColGenerator.java @@ -34,6 +34,7 @@ public SeqColLevelOneEntity generateLevelOneEntity() { jsonLevelOne.setMd5DigestsOfSequences("_6iaYtcWw4TZaowlL7_64Wu9mbHpDUw4"); jsonLevelOne.setSortedNameLengthPairs("QFuKs5Hh8uQwwUtnRxIf8W3zeJoFOp8Z"); levelOneEntity.setSeqColLevel1Object(jsonLevelOne); + levelOneEntity.setDigest("3mTg0tAA3PS-R1TzelLVWJ2ilUzoWfVq"); levelOneEntity.addMetadata(metadata); return levelOneEntity; }