Skip to content

Commit 80674aa

Browse files
Merge pull request #93 from sundarvenkata-EBI/ops/spring2_upgrade
EVA-1905 - Spring 2 upgrade
2 parents 89ee17b + d53bd66 commit 80674aa

File tree

47 files changed

+560
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+560
-457
lines changed

.travis.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ dist: xenial
44

55
language: java
66

7-
jdk:
8-
- openjdk8
7+
matrix:
8+
include:
9+
- language: "java"
10+
jdk: openjdk8
11+
env:
12+
- OPENCGA_HOME=$TRAVIS_BUILD_DIR/opencga/opencga-app/build
13+
- MONGODB_VERSION=4.0.18
14+
install:
15+
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-$MONGODB_VERSION.tgz
16+
- tar xfz mongodb-linux-x86_64-$MONGODB_VERSION.tgz
17+
- export PATH=`pwd`/mongodb-linux-x86_64-$MONGODB_VERSION/bin:$PATH
18+
- mkdir -p data/db
19+
- mongod --dbpath=data/db &
20+
- mongod --version
921

10-
env:
11-
- OPENCGA_HOME=$TRAVIS_BUILD_DIR/opencga/opencga-app/build
1222

pom.xml

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<properties>
2020
<java.version>1.8</java.version>
21-
<spring.boot.version>1.4.2.RELEASE</spring.boot.version>
21+
<spring.boot.version>2.1.0.RELEASE</spring.boot.version>
2222
</properties>
2323

2424
<dependencyManagement>
@@ -43,12 +43,6 @@
4343
<scope>test</scope>
4444
<version>0.14.0</version>
4545
</dependency>
46-
<dependency>
47-
<groupId>com.github.fakemongo</groupId>
48-
<artifactId>fongo</artifactId>
49-
<scope>test</scope>
50-
<version>2.1.0</version>
51-
</dependency>
5246
<dependency>
5347
<groupId>javax.validation</groupId>
5448
<artifactId>validation-api</artifactId>
@@ -75,7 +69,6 @@
7569
<dependency>
7670
<groupId>org.springframework.boot</groupId>
7771
<artifactId>spring-boot-starter-data-mongodb</artifactId>
78-
<version>1.4.2.RELEASE</version>
7972
</dependency>
8073

8174
<dependency>

variation-commons-jpa/src/test/java/uk/ac/ebi/eva/commons/jpa/models/metadata/database/FileDatabaseTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.junit.Test;
2020
import org.junit.runner.RunWith;
2121
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.orm.jpa.JpaSystemException;
22+
import org.springframework.dao.DataIntegrityViolationException;
2323
import org.springframework.test.context.ContextConfiguration;
2424
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2525
import org.springframework.transaction.annotation.Transactional;
@@ -132,7 +132,7 @@ public void testDelete() {
132132
*
133133
* @todo How to report this kind of errors?
134134
*/
135-
@Test(expected = JpaSystemException.class)
135+
@Test(expected = DataIntegrityViolationException.class)
136136
public void testUpdateDuplicate() {
137137
File savedFile1 = repository.save(file1);
138138
File savedFile2 = repository.save(file2);

variation-commons-jpa/src/test/java/uk/ac/ebi/eva/commons/jpa/models/metadata/database/OrganisationDatabaseTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.junit.Test;
2020
import org.junit.runner.RunWith;
2121
import org.springframework.beans.factory.annotation.Autowired;
22-
import org.springframework.orm.jpa.JpaSystemException;
22+
import org.springframework.dao.DataIntegrityViolationException;
2323
import org.springframework.test.context.ContextConfiguration;
2424
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2525
import org.springframework.transaction.annotation.Transactional;
@@ -154,7 +154,7 @@ public void testUpdateNonDuplicate() {
154154
*
155155
* @todo How to report this kind of errors?
156156
*/
157-
@Test(expected = JpaSystemException.class)
157+
@Test(expected = DataIntegrityViolationException.class)
158158
public void testUpdateDuplicate() {
159159
Organisation savedOrganisation1 = repository.save(organisation1);
160160
Organisation savedOrganisation2 = repository.save(organisation2);

variation-commons-jpa/src/test/java/uk/ac/ebi/eva/commons/jpa/models/metadata/database/PublicationDatabaseTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.junit.Test;
55
import org.junit.runner.RunWith;
66
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.orm.jpa.JpaSystemException;
7+
import org.springframework.dao.DataIntegrityViolationException;
88
import org.springframework.test.context.ContextConfiguration;
99
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
1010
import org.springframework.transaction.annotation.Transactional;
@@ -192,7 +192,7 @@ public void testUpdateNonDuplicate() {
192192
*
193193
* @todo How to report this kind of errors?
194194
*/
195-
@Test(expected = JpaSystemException.class)
195+
@Test(expected = DataIntegrityViolationException.class)
196196
public void testUpdateDuplicate() {
197197
Publication savedPublication1 = repository.save(publication1);
198198
Publication savedPublication3 = repository.save(publication3);

variation-commons-jpa/src/test/java/uk/ac/ebi/eva/commons/jpa/models/metadata/database/StudyDatabaseTest.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@
3030
import uk.ac.ebi.eva.commons.jpa.models.metadata.Organisation;
3131
import uk.ac.ebi.eva.commons.jpa.models.metadata.Study;
3232

33+
import java.util.Optional;
34+
3335
import static org.hamcrest.Matchers.containsInAnyOrder;
3436
import static org.hamcrest.Matchers.empty;
3537
import static org.junit.Assert.assertEquals;
3638
import static org.junit.Assert.assertNotEquals;
3739
import static org.junit.Assert.assertNotNull;
3840
import static org.junit.Assert.assertThat;
41+
import static org.junit.Assert.assertTrue;
3942

4043
@RunWith(SpringJUnit4ClassRunner.class)
4144
@Transactional
@@ -207,11 +210,13 @@ public void addOneAnalisysToManyStudies() {
207210
assertEquals(study2, savedStudy2);
208211

209212
// check that just study2 has a file generator, and that file generator is the analysis 1
210-
Study studyFromRepository1 = repository.findOne(savedStudy1.getId());
211-
Study studyFromRepository2 = repository.findOne(savedStudy2.getId());
212-
assertEquals(studyFromRepository1.getFileGenerators().size(), 0);
213-
assertEquals(studyFromRepository2.getFileGenerators().size(), 1);
214-
assertEquals(studyFromRepository2.getFileGenerators().iterator().next(), analysis1);
213+
Optional<Study> studyFromRepository1 = repository.findById(savedStudy1.getId());
214+
Optional<Study> studyFromRepository2 = repository.findById(savedStudy2.getId());
215+
assertTrue(studyFromRepository1.isPresent());
216+
assertTrue(studyFromRepository2.isPresent());
217+
assertEquals(studyFromRepository1.get().getFileGenerators().size(), 0);
218+
assertEquals(studyFromRepository2.get().getFileGenerators().size(), 1);
219+
assertEquals(studyFromRepository2.get().getFileGenerators().iterator().next(), analysis1);
215220

216221
// check that just one analysis have been saved and that can be retrieved using Analysis
217222
// and FileGenerator repositories

variation-commons-jpa/src/test/java/uk/ac/ebi/eva/commons/jpa/models/metadata/database/StudyRelationDatabaseTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void testMultipleChildren() {
9898
checkChildStudiesInParent(parentStudy1, childStudies);
9999
checkParentStudiesInChildren(parentStudy1, childStudies);
100100

101-
Iterable<Study> savedChildStudies = repository.save(childStudies);
101+
Iterable<Study> savedChildStudies = repository.saveAll(childStudies);
102102
checkChildStudiesInParent(parentStudy1, new HashSet<>((Collection<Study>) savedChildStudies));
103103
checkParentStudiesInChildren(parentStudy1, savedChildStudies);
104104

variation-commons-mongodb/pom.xml

-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
<artifactId>nosqlunit-mongodb</artifactId>
2626
<scope>test</scope>
2727
</dependency>
28-
<dependency>
29-
<groupId>com.github.fakemongo</groupId>
30-
<artifactId>fongo</artifactId>
31-
<scope>test</scope>
32-
</dependency>
3328
<dependency>
3429
<groupId>uk.ac.ebi.eva</groupId>
3530
<artifactId>variation-commons-core</artifactId>

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/configuration/EvaRepositoriesConfiguration.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package uk.ac.ebi.eva.commons.mongodb.configuration;
1717

1818
import org.springframework.beans.factory.annotation.Autowired;
19-
import org.springframework.beans.factory.annotation.Value;
2019
import org.springframework.context.ApplicationContext;
2120
import org.springframework.context.annotation.Bean;
2221
import org.springframework.context.annotation.ComponentScan;

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/entities/AnnotationMetadataMongo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Mapped class for annotations metadata collection in mongo
2626
*/
27-
@Document(collection = "#{mongoCollectionsAnnotationMetadata}")
27+
@Document(collection = "#{@mongoCollectionsAnnotationMetadata}")
2828
public class AnnotationMetadataMongo implements IAnnotationMetadata {
2929

3030
private static final String VEP_VERSION_FIELD = "vepv";

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/entities/AnnotationMongo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/**
3232
* Mapped class for annotations collection in mongo
3333
*/
34-
@Document(collection = "#{mongoCollectionsAnnotations}")
34+
@Document(collection = "#{@mongoCollectionsAnnotations}")
3535
public class AnnotationMongo implements IAnnotation {
3636

3737
public static final String CHROMOSOME_FIELD = "chr";

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/entities/FeatureCoordinatesMongo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* Mapped class for feature collection in mongo
2525
*/
26-
@Document(collection = "#{mongoCollectionsFeatures}")
26+
@Document(collection = "#{@mongoCollectionsFeatures}")
2727
public class FeatureCoordinatesMongo implements IFeatureCoordinates {
2828

2929
//TODO check if these are the intended names for the database structure

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/entities/SampleMongo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import java.util.Set;
2424

25-
@Document(collection = "#{mongoCollectionsSamples}")
25+
@Document(collection = "#{@mongoCollectionsSamples}")
2626
public class SampleMongo {
2727

2828
public static final String SEX_FIELD = "sex";

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/entities/VariantMongo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/**
4040
* Mapped class for variant collection in mongo
4141
*/
42-
@Document(collection = "#{mongoCollectionsVariants}")
42+
@Document(collection = "#{@mongoCollectionsVariants}")
4343
public class VariantMongo {
4444

4545
private static final int CHUNK_SIZE_SMALL = 1000;

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/entities/VariantSourceMongo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* Mapped class for variant source collection in mongo
3434
*/
35-
@Document(collection = "#{mongoCollectionsFiles}")
35+
@Document(collection = "#{@mongoCollectionsFiles}")
3636
public class VariantSourceMongo implements IVariantSource {
3737

3838
public final static String FILEID_FIELD = "fid";

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/entities/subdocuments/VariantSourceEntryMongo.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*/
1616
package uk.ac.ebi.eva.commons.mongodb.entities.subdocuments;
1717

18-
import com.mongodb.BasicDBObject;
18+
import org.bson.Document;
1919
import org.slf4j.Logger;
2020
import org.slf4j.LoggerFactory;
2121
import org.springframework.data.mongodb.core.mapping.Field;
22+
2223
import uk.ac.ebi.eva.commons.core.models.IVariantSourceEntry;
2324
import uk.ac.ebi.eva.commons.core.models.genotype.Genotype;
2425
import uk.ac.ebi.eva.commons.core.utils.CompressionHelper;
@@ -66,7 +67,7 @@ public class VariantSourceEntryMongo {
6667
private String[] alternates;
6768

6869
@Field(ATTRIBUTES_FIELD)
69-
private BasicDBObject attributes;
70+
private Document attributes;
7071

7172
@Field(FORMAT_FIELD)
7273
private String format;
@@ -115,7 +116,7 @@ public VariantSourceEntryMongo(String fileId, String studyId, String[] alternate
115116
}
116117
}
117118

118-
private BasicDBObject buildSampleData(List<Map<String, String>> samplesData) {
119+
private Document buildSampleData(List<Map<String, String>> samplesData) {
119120
Map<Genotype, List<Integer>> genotypeCodes = classifySamplesByGenotype(samplesData);
120121

121122
// Get the most common genotype
@@ -127,7 +128,7 @@ private BasicDBObject buildSampleData(List<Map<String, String>> samplesData) {
127128
// "def" : 0|0,
128129
// "0|1" : [ 41, 311, 342, 358, 881, 898, 903 ],
129130
// "1|0" : [ 262, 290, 300, 331, 343, 369, 374, 391, 879, 918, 930 ]
130-
BasicDBObject mongoSamples = new BasicDBObject();
131+
Document mongoSamples = new Document();
131132
if (mostCommonGenotype != null) {
132133
mongoSamples.append(DEFAULT, mostCommonGenotype.generateDatabaseString());
133134
}
@@ -172,8 +173,8 @@ private Map<Genotype, List<Integer>> classifySamplesByGenotype(List<Map<String,
172173
return genotypeCodes;
173174
}
174175

175-
private BasicDBObject buildAttributes(Map<String, String> attributes) {
176-
BasicDBObject attrs = null;
176+
private Document buildAttributes(Map<String, String> attributes) {
177+
Document attrs = null;
177178
for (Map.Entry<String, String> entry : attributes.entrySet()) {
178179
Object value = entry.getValue();
179180
if (entry.getKey().equals("src")) {
@@ -191,7 +192,7 @@ private BasicDBObject buildAttributes(Map<String, String> attributes) {
191192
}
192193

193194
if (attrs == null) {
194-
attrs = new BasicDBObject(entry.getKey().replace('.', CHARACTER_TO_REPLACE_DOTS), value);
195+
attrs = new Document(entry.getKey().replace('.', CHARACTER_TO_REPLACE_DOTS), value);
195196
} else {
196197
attrs.append(entry.getKey().replace('.', CHARACTER_TO_REPLACE_DOTS), value);
197198
}

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/repositories/AnnotationMetadataRepository.java

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package uk.ac.ebi.eva.commons.mongodb.repositories;
1717

1818
import org.springframework.data.mongodb.repository.MongoRepository;
19+
import org.springframework.stereotype.Repository;
1920

2021
import uk.ac.ebi.eva.commons.mongodb.entities.AnnotationMetadataMongo;
2122

@@ -24,6 +25,7 @@
2425
/**
2526
* Spring MongoRepository for querying collection of AnnotationMetadataMongo documents
2627
*/
28+
@Repository
2729
public interface AnnotationMetadataRepository extends MongoRepository<AnnotationMetadataMongo, String> {
2830

2931
/**

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/repositories/AnnotationRepository.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package uk.ac.ebi.eva.commons.mongodb.repositories;
1717

1818
import org.springframework.data.mongodb.repository.MongoRepository;
19+
import org.springframework.stereotype.Repository;
1920

2021
import uk.ac.ebi.eva.commons.core.models.IAnnotationMetadata;
2122
import uk.ac.ebi.eva.commons.mongodb.entities.AnnotationMongo;
@@ -31,6 +32,7 @@
3132
/**
3233
* Repository to access the annotation collection.
3334
*/
35+
@Repository
3436
public interface AnnotationRepository extends MongoRepository<AnnotationMongo, String> {
3537

3638
Set<AnnotationMongo> findByIdIn(Collection<String> ids);
@@ -77,14 +79,14 @@ default Map<String, AnnotationMongo> findAndIndexAnnotationsOfVariants(List<Vari
7779

7880

7981
default AnnotationMongo findOne(String chromosome, long start, String referenceAllele, String alternativeAllele,
80-
String vepVersion, String vepCacheVersion) {
81-
return findOne(AnnotationMongo.buildAnnotationId(
82-
chromosome,
83-
start,
84-
referenceAllele,
85-
alternativeAllele,
86-
vepVersion,
87-
vepCacheVersion));
82+
String vepVersion, String vepCacheVersion) {
83+
return findById(AnnotationMongo.buildAnnotationId(chromosome,
84+
start,
85+
referenceAllele,
86+
alternativeAllele,
87+
vepVersion,
88+
vepCacheVersion)).get();
89+
8890
}
8991

9092
}

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/repositories/FeatureRepository.java

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package uk.ac.ebi.eva.commons.mongodb.repositories;
1717

1818
import org.springframework.data.mongodb.repository.MongoRepository;
19+
import org.springframework.stereotype.Repository;
20+
1921
import uk.ac.ebi.eva.commons.mongodb.entities.FeatureCoordinatesMongo;
2022

2123
import java.util.List;
@@ -26,6 +28,7 @@
2628
* This interface is used by Spring to create the query methods for features.
2729
* Spring creates the implementation automatically by looking at the method name.
2830
*/
31+
@Repository
2932
public interface FeatureRepository extends MongoRepository<FeatureCoordinatesMongo, String> {
3033

3134
List<FeatureCoordinatesMongo> findByIdOrName(String id, String name);

variation-commons-mongodb/src/main/java/uk/ac/ebi/eva/commons/mongodb/repositories/VariantRepository.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121
import org.springframework.data.domain.Sort;
2222
import org.springframework.data.mongodb.repository.MongoRepository;
2323
import org.springframework.data.mongodb.repository.Query;
24+
import org.springframework.stereotype.Repository;
25+
2426
import uk.ac.ebi.eva.commons.core.models.VariantType;
2527
import uk.ac.ebi.eva.commons.mongodb.entities.VariantMongo;
2628

2729
import java.util.List;
30+
import java.util.stream.Stream;
2831

2932
/**
3033
* Spring MongoRepository for {@link VariantMongo} class.
3134
* <p>
3235
* Methods include querying by id, and by region.
3336
*/
37+
@Repository
3438
public interface VariantRepository extends MongoRepository<VariantMongo, String>,
3539
VariantRepositoryCustom {
3640

@@ -59,5 +63,9 @@ List<VariantMongo> findByChromosomeAndStartAndTypeAndStudyIn(String chr, long st
5963
List<String> studyIds);
6064

6165
@Query(value = "{'chr': ?0, 'files.sid': {$in : ?1}}}")
62-
VariantMongo findOneByChromosomeAndStudyInSorted(String chr, List<String> studyIds, Sort sort);
66+
Stream<VariantMongo> findAllByChromosomeAndStudyInSorted(String chr, List<String> studyIds, Sort sort);
67+
68+
default VariantMongo findOneByChromosomeAndStudyInSorted(String chr, List<String> studyIds, Sort sort) {
69+
return findAllByChromosomeAndStudyInSorted(chr, studyIds, sort).findFirst().orElse(null);
70+
}
6371
}

0 commit comments

Comments
 (0)