Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive approach #113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@
<version>1.2.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.3.4</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -178,6 +190,23 @@
</includeOnlyProperties>
</configuration>
</plugin>

<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<version>5.4.1.Final</version>
<executions>
<execution>
<configuration>
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
</configuration>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

<resources>
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/uk/ac/ebi/eva/contigalias/entities/JSONObjectL1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package uk.ac.ebi.eva.contigalias.entities;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class JSONObjectL1 implements Serializable {
private String sequences;
private String names;
private String lengths;
}
















18 changes: 18 additions & 0 deletions src/main/java/uk/ac/ebi/eva/contigalias/entities/JSONObjectL2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package uk.ac.ebi.eva.contigalias.entities;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class JSONObjectL2 implements Serializable {
private List<Integer> lengths; // Level 2 lengths array
private List<String> names; // Level 2 names array
private List<String> sequences; // Level 2 sequences array

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package uk.ac.ebi.eva.contigalias.entities;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.persistence.*;
import java.util.List;

@Entity
@Data
@NoArgsConstructor
@ToString
@Table(name = "naming_conventions")
public class NamingConvention {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Convention convention;

@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "digest", referencedColumnName = "digest")
private SeqColL1 seqColL1;

/*@OneToOne
@JoinColumn(name = "digest")
private SeqColL1 seqCols;*/

public enum Convention {
ENA, GENBANK
}

public NamingConvention(Convention convention, SeqColL1 seqColL1){
this.convention = convention;
this.seqColL1 = seqColL1;
}
}
28 changes: 28 additions & 0 deletions src/main/java/uk/ac/ebi/eva/contigalias/entities/SeqCol.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.ac.ebi.eva.contigalias.entities;

import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;

import javax.persistence.*;
import java.util.List;

@MappedSuperclass
@TypeDefs({
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
@AllArgsConstructor
@NoArgsConstructor
@ToString
public abstract class SeqCol {

@Id
@Column (name = "digest")
protected String digest; // The level 0 digest

/*@Transient
protected NamingConvention.Convention namingConvention;*/
}
31 changes: 31 additions & 0 deletions src/main/java/uk/ac/ebi/eva/contigalias/entities/SeqColL1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.ac.ebi.eva.contigalias.entities;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.*;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Data
@Table(name = "sequence_collections_L1")
public class SeqColL1 extends SeqCol{

@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
@Basic(fetch = FetchType.LAZY)
private JSONObjectL1 object;

@OneToOne(mappedBy = "seqColL1")
private NamingConvention namingConvention;

public SeqColL1(String digest, JSONObjectL1 jsonObject, NamingConvention namingConvention){
super(digest);
this.namingConvention = namingConvention;
this.object = jsonObject;
}

}
26 changes: 26 additions & 0 deletions src/main/java/uk/ac/ebi/eva/contigalias/entities/SeqColL2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package uk.ac.ebi.eva.contigalias.entities;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.*;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@Data
@Table(name = "sequence_collections_L2")
public class SeqColL2 extends SeqCol{

@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
@Basic(fetch = FetchType.LAZY)
private JSONObjectL2 object;

public SeqColL2(String digest, JSONObjectL2 jsonObject, NamingConvention.Convention namingConvention){
super(digest);
this.object = jsonObject;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package uk.ac.ebi.eva.contigalias.repo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import uk.ac.ebi.eva.contigalias.entities.NamingConvention;
@Repository
public interface NamingConventionRepository extends JpaRepository<NamingConvention, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package uk.ac.ebi.eva.contigalias.repo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import uk.ac.ebi.eva.contigalias.entities.SeqColL1;
@Repository
public interface SeqColL1Repository extends JpaRepository<SeqColL1, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package uk.ac.ebi.eva.contigalias.repo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import uk.ac.ebi.eva.contigalias.entities.SeqColL2;

@Repository
public interface SeqColL2Repository extends JpaRepository<SeqColL2, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package uk.ac.ebi.eva.contigalias.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.eva.contigalias.entities.NamingConvention;
import uk.ac.ebi.eva.contigalias.repo.NamingConventionRepository;

import java.util.Optional;

@Service
public class NamingConventionService {

@Autowired
private NamingConventionRepository repository;


public Optional<NamingConvention> addNamingConvention(NamingConvention namingConvention){
NamingConvention convention = repository.save(namingConvention);
return Optional.of(convention);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package uk.ac.ebi.eva.contigalias.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.eva.contigalias.entities.SeqColL1;
import uk.ac.ebi.eva.contigalias.repo.SeqColL1Repository;

import java.util.Optional;

@Service
public class SeqColL1Service {

@Autowired
private SeqColL1Repository repository;

/**
* Add a new Level 1 sequence collection object and save it to the
* database*/
public Optional<SeqColL1> addSequenceCollectionL1(SeqColL1 seqColL1){
SeqColL1 seqCol = repository.save(seqColL1);
return Optional.of(seqCol);
}

public Optional<SeqColL1> getSeqColL1ByDigest(String digest){
Optional<SeqColL1> seqColL11 = repository.findById(digest);
return seqColL11;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package uk.ac.ebi.eva.contigalias.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.eva.contigalias.entities.SeqColL2;
import uk.ac.ebi.eva.contigalias.repo.SeqColL2Repository;

import java.util.Optional;

@Service
public class SeqColL2Service {

@Autowired
private SeqColL2Repository repository;

public Optional<SeqColL2> addSequenceCollectionL2(SeqColL2 seqColL2){
SeqColL2 seqCol = repository.save(seqColL2);
return Optional.of(seqCol);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.ac.ebi.eva.contigalias.service;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import uk.ac.ebi.eva.contigalias.entities.NamingConvention;

import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class NamingConventionServiceTest {

@Autowired
private NamingConventionService namingConventionService;

private static NamingConvention namingConvention;

private final NamingConvention.Convention CONVENTION = NamingConvention.Convention.GENBANK;

private final static String DIGEST0 = "a6748aa0f6a1e165f871dbed5e54ba62";
@BeforeEach
void setUp() {
}

@AfterEach
void tearDown() {
}

@Test
void addNamingConvention() {
}
}
Loading