Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2019 EMBL - European Bioinformatics Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ebi.eva.commons.core.models;

/**
* Base implementation of {@link IDefaultLocusRangeMetadata}
*/
public class DefaultLocusRangeMetadata implements IDefaultLocusRangeMetadata {

private String chromosome;

private long start;

private long end;

public DefaultLocusRangeMetadata() {

}

public DefaultLocusRangeMetadata(IDefaultLocusRangeMetadata defaultLocusRangeMetadata) {
this(defaultLocusRangeMetadata.getChromosome(), defaultLocusRangeMetadata.getStart(),
defaultLocusRangeMetadata.getEnd());
}

public DefaultLocusRangeMetadata(String chromosome, long start, long end) {
this.chromosome = chromosome;
this.start = start;
this.end = end;
}

@Override
public String getChromosome() {
return chromosome;
}

@Override
public long getStart() {
return start;
}

@Override
public long getEnd() {
return end;
}

@Override
public String toString() {
return "DefaultLocusRangeMetadata{" +
"chromosome='" + chromosome + '\'' +
", start='" + start + '\'' +
", end='" + end + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

DefaultLocusRangeMetadata that = (DefaultLocusRangeMetadata) o;

if (start != that.start) return false;
if (end != that.end) return false;
return chromosome.equals(that.chromosome);
}

@Override
public int hashCode() {
int result = chromosome.hashCode();
result = 31 * result + (int) (start ^ (start >>> 32));
result = 31 * result + (int) (end ^ (end >>> 32));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2019 EMBL - European Bioinformatics Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ebi.eva.commons.core.models;

public interface IDefaultLocusRangeMetadata {

String getChromosome();

long getStart();

long getEnd();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright 2019 EMBL - European Bioinformatics Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ebi.eva.commons.mongodb.entities;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import uk.ac.ebi.eva.commons.core.models.IDefaultLocusRangeMetadata;

/**
* Mapped class for annotations metadata collection in mongo
*/
@Document(collection = "#{mongoCollectionsDefaultLocusRangeMetadata}")
public class DefaultLocusRangeMetadataMongo implements IDefaultLocusRangeMetadata {

private static final String CHROMOSOME_FIELD = "chr";

private static final String START_FIELD = "start";

private static final String END_FIELD = "end";

@Id
private String id;

@Field(CHROMOSOME_FIELD)
private String chromosome;

@Field(START_FIELD)
private long start;

@Field(END_FIELD)
private long end;

DefaultLocusRangeMetadataMongo() {
// Empty document constructor for spring-data
}

public DefaultLocusRangeMetadataMongo(String id, String chromosome, long start, long end) {
this.id = id;
this.chromosome = chromosome;
this.start = start;
this.end = end;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getChromosome() {
return chromosome;
}

public long getStart() {
return start;
}

public long getEnd() {
return end;
}

@Override
public String toString() {
return "DefaultLocusRangeMetadataMongo{" +
"chromosome='" + chromosome + '\'' +
", start='" + start + '\'' +
", end='" + end + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

DefaultLocusRangeMetadataMongo that = (DefaultLocusRangeMetadataMongo) o;

if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (start != that.start) return false;
if (end != that.end) return false;
return chromosome.equals(that.chromosome);
}

@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (chromosome != null ? chromosome.hashCode() : 0);
result = 31 * result + (int) (start ^ (start >>> 32));
result = 31 * result + (int) (end ^ (end >>> 32));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2019 EMBL - European Bioinformatics Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ebi.eva.commons.mongodb.repositories;

import org.springframework.data.mongodb.repository.MongoRepository;
import uk.ac.ebi.eva.commons.mongodb.entities.DefaultLocusRangeMetadataMongo;

import java.util.List;

/**
* Spring MongoRepository for querying collection of DefaultLocusRangeMetadataMongo documents
*/
public interface DefaultLocusRangeMetadataRepository extends MongoRepository<DefaultLocusRangeMetadataMongo, String> {

/**
* Query for all DefaultLocusRangeMetadataMongo from collection
*
* @return List of DefaultLocusRangeMetadataMongo objects
*/
List<DefaultLocusRangeMetadataMongo> findAllByOrderByChromosomeAscStartAscEndAsc();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2019 EMBL - European Bioinformatics Institute
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ebi.eva.commons.mongodb.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import uk.ac.ebi.eva.commons.core.models.DefaultLocusRangeMetadata;
import uk.ac.ebi.eva.commons.mongodb.entities.DefaultLocusRangeMetadataMongo;
import uk.ac.ebi.eva.commons.mongodb.repositories.DefaultLocusRangeMetadataRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
* Mongo persistence service to access {@link DefaultLocusRangeMetadata}
*/
@Service
public class DefaultLocusRangeMetadataService {

@Autowired
private DefaultLocusRangeMetadataRepository repository;

public List<DefaultLocusRangeMetadata> findAllByOrderByChromosomeAscStartAscEndAsc() {
return convert(repository.findAllByOrderByChromosomeAscStartAscEndAsc());
}

private List<DefaultLocusRangeMetadata> convert(List<DefaultLocusRangeMetadataMongo> defaultLocusRangeMetadatas) {
return defaultLocusRangeMetadatas.stream().map(DefaultLocusRangeMetadata::new).collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ public class DatabaseTestConfiguration {
@Value("${db.collections.annotation-metadata.name}")
public String mongoCollectionsAnnotationMetadata;

@Value("${db.collections.default-locus-range-metadata.name}")
public String mongoCollectionsDefaultLocusRangeMetadata;

@Bean
public String mongoCollectionsAnnotationMetadata() {
return mongoCollectionsAnnotationMetadata;
}

@Bean
public String mongoCollectionsDefaultLocusRangeMetadata() {
return mongoCollectionsDefaultLocusRangeMetadata;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public String mongoCollectionsAnnotationMetadata(
return collectionAnnotationMetadata;
}

@Bean
public String mongoCollectionsDefaultLocusRangeMetadata(
@Value("${eva.mongo.collections.default-locus-range-metadata:#{null}}")
String collectionDefaultLocusRangeMetadata) {
Assert.notNull(collectionDefaultLocusRangeMetadata);
return collectionDefaultLocusRangeMetadata;
}

@Bean
public String mongoCollectionsAnnotations(
@Value("${eva.mongo.collections.annotations:#{null}}") String collectionAnnotations) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package uk.ac.ebi.eva.commons.mongodb.repositories;

import com.lordofthejars.nosqlunit.annotation.UsingDataSet;
import com.lordofthejars.nosqlunit.mongodb.MongoDbRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import uk.ac.ebi.eva.commons.mongodb.configuration.MongoRepositoryTestConfiguration;
import uk.ac.ebi.eva.commons.mongodb.entities.DefaultLocusRangeMetadataMongo;

import java.util.List;

import static com.lordofthejars.nosqlunit.mongodb.MongoDbRule.MongoDbRuleBuilder.newMongoDbRule;
import static org.junit.Assert.*;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {MongoRepositoryTestConfiguration.class})
@UsingDataSet(locations = {"/test-data/defaultLocusRange.json"})
public class DefaultLocusRangeMetadataRepositoryTest {

@Autowired
private ApplicationContext applicationContext;

@Rule
public MongoDbRule mongoDbRule = newMongoDbRule().defaultSpringMongoDb("test-db");

@Autowired
private DefaultLocusRangeMetadataRepository repository;

@Test
public void findOneByDefault() throws Exception {
List<DefaultLocusRangeMetadataMongo> defaultLocusRangeMetadataMongoList =
repository.findAllByOrderByChromosomeAscStartAscEndAsc();
assertEquals(1, defaultLocusRangeMetadataMongoList.size());
}
}
Loading