forked from EBIvariation/eva-seqcol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
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
1 parent
07a38d8
commit b80c755
Showing
13 changed files
with
195 additions
and
26 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
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
67 changes: 67 additions & 0 deletions
67
src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadata.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,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; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColMetadataId.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,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.. | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/uk/ac/ebi/eva/evaseqcol/exception/DuplicateSeqColWithDifferentMetadata.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,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"); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/uk/ac/ebi/eva/evaseqcol/repo/MetadataRepository.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,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<SeqColMetadata, SeqColMetadataId> { | ||
|
||
List<SeqColMetadata> findAllBySeqColDigest(String digest); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/uk/ac/ebi/eva/evaseqcol/service/MetadataService.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,35 @@ | ||
package uk.ac.ebi.eva.evaseqcol.service; | ||
|
||
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.repo.MetadataRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class MetadataService { | ||
|
||
@Autowired | ||
private MetadataRepository repository; | ||
|
||
public Optional<SeqColMetadata> 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<List<SeqColMetadata>> getAllMetadataForSeqColByDigest(String seqColDigest) { | ||
return Optional.of( | ||
repository.findAllBySeqColDigest(seqColDigest) | ||
); | ||
} | ||
} |
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