Skip to content

Commit

Permalink
Merge pull request #43 from waterflow80/service-info
Browse files Browse the repository at this point in the history
Implemented the service-info endpoint
  • Loading branch information
waterflow80 authored Aug 26, 2023
2 parents 5ee3bc8 + a79961e commit ad28ad8
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity;
import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity;
import uk.ac.ebi.eva.evaseqcol.exception.SeqColNotFoundException;
import uk.ac.ebi.eva.evaseqcol.exception.UnableToLoadServiceInfoException;
import uk.ac.ebi.eva.evaseqcol.service.SeqColService;

import java.io.IOException;
import java.util.Map;
import java.util.Optional;

@RestController
@RequestMapping("/collection")
@RequestMapping("/")
public class SeqColController {

private SeqColService seqColService;
Expand All @@ -28,7 +31,7 @@ public SeqColController(SeqColService seqColService) {
this.seqColService = seqColService;
}

@GetMapping(value = "/{digest}")
@GetMapping(value = "/collection/{digest}")
public ResponseEntity<?> getSeqColByDigestAndLevel(
@PathVariable String digest, @RequestParam(required = false) String level) {
if (level == null) level = "none";
Expand Down Expand Up @@ -60,4 +63,13 @@ public ResponseEntity<?> getSeqColByDigestAndLevel(
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

@GetMapping("/service-info")
public ResponseEntity<?> getServiceInfo() {
try {
Map<String, Object> serviceInfoMap = seqColService.getServiceInfo();
return new ResponseEntity<>(serviceInfoMap, HttpStatus.OK);
} catch (UnableToLoadServiceInfoException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/uk/ac/ebi/eva/evaseqcol/entities/SeqColId.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package uk.ac.ebi.eva.evaseqcol.entities;

import com.sun.istack.NotNull;
import lombok.EqualsAndHashCode;

import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import java.io.Serializable;

@EqualsAndHashCode
public class SeqColId implements Serializable {
@NotNull
private String digest;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package uk.ac.ebi.eva.evaseqcol.exception;

public class UnableToLoadServiceInfoException extends RuntimeException {

public UnableToLoadServiceInfoException(String serviceInfoFilePath) {
super("Unable to load service-info file: " + serviceInfoFilePath);
}
}
17 changes: 17 additions & 0 deletions src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -15,6 +16,7 @@
import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity;
import uk.ac.ebi.eva.evaseqcol.exception.DuplicateSeqColException;
import uk.ac.ebi.eva.evaseqcol.exception.SeqColNotFoundException;
import uk.ac.ebi.eva.evaseqcol.exception.UnableToLoadServiceInfoException;
import uk.ac.ebi.eva.evaseqcol.utils.JSONExtData;
import uk.ac.ebi.eva.evaseqcol.utils.SeqColMapConverter;

Expand All @@ -36,6 +38,8 @@
@Service
public class SeqColService {

@Value("${service.info.file.path}")
private String SERVICE_INFO_FILE_PATH;
private final NCBISeqColDataSource ncbiSeqColDataSource;
private final SeqColLevelOneService levelOneService;
private final SeqColLevelTwoService levelTwoService;
Expand Down Expand Up @@ -109,6 +113,19 @@ public Optional<? extends SeqColEntity> getSeqColByDigestAndLevel(String digest,
}
}

/**
* Return the service info entity in a Map<String,Object> format
* @see 'https://seqcol.readthedocs.io/en/dev/specification/#21-service-info'
* for more details about the service-info*/
public Map<String, Object> getServiceInfo() {
try {
Map<String, Object> serviceInfoMap = SeqColMapConverter.jsonToMap(SERVICE_INFO_FILE_PATH);
return serviceInfoMap;
} catch (IOException e) {
throw new UnableToLoadServiceInfoException(SERVICE_INFO_FILE_PATH);
}
}

/**
* Full remove of the seqCol object (level one and its extended data)*/
@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package uk.ac.ebi.eva.evaseqcol.utils;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;

import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity;
import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -34,4 +37,18 @@ public static Map<String, List<String>> getSeqColLevelTwoMap(SeqColLevelTwoEntit
return seqColMap;
}

/**
* Read the json file for the given filePath and return Map representation of
* its content*/
public static Map<String, Object> jsonToMap(String filePath) throws IOException {
File file = new File(filePath);
Map<String, Object> jsonMap = null;


ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
jsonMap=mapper.readValue(file, Map.class);

return jsonMap;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ [email protected]@
config.scaffolds.enabled = @contig-alias.scaffolds-enabled@

asm.file.download.dir=/tmp
service.info.file.path=src/main/resources/static/service-info.json

# remove spring data browsing endpoints (https://docs.spring.io/spring-data/rest/docs/3.3.x/reference/html/#getting-started.setting-repository-detection-strategy)
spring.data.rest.detection-strategy=annotated
Expand Down
77 changes: 77 additions & 0 deletions src/main/resources/static/service-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"id": "uk.ebi.eva.eva-seqcol",
"name": "Implementation of the GA4GH Sequence collection retrieval API",
"type": {
"group": "org.ga4gh",
"artifact": "seqcol",
"version": "1.0.0"
},
"organization": {
"name": "European Variation Archive",
"url": "https://www.ebi.ac.uk/eva"
},
"contactUrl": "mailto:[email protected]",
"documentationUrl": "https://www.ebi.ac.uk/eva/....",
"updatedAt": "08-24-2023",
"environment": "dev",
"version": "1.0.0",
"seqcol": {
"schema": {
"description": "A collection of sequences, representing biological sequences including nucleotide or amino acid sequences. For example, a sequence collection may represent the set of chromosomes in a reference genome, the set of transcripts in a transcriptome, a collection of reference microbial sequences of a specific gene, or any other set of sequences.",
"type": "object",
"properties":{
"lengths":{
"type": "array",
"description": "Number of elements, such as nucleotides or amino acids, in each sequence.",
"collated": "true",
"items":{
"type": "string"
}
},
"names":{
"type": "array",
"description": "Human-readable identifiers of each sequence, commonly called chromosome names.",
"collated": "true",
"items":{
"type": "string"
}
},
"sequences":{
"type": "array",
"description": "Digests of sequences computed using the GA4GH digest algorithm (sha512t24u).",
"collated": "true",
"items":{
"type": "string"
}
},
"md5-sequences":{
"type": "array",
"description": "Digests of sequences computed using md5 digest algorithm.",
"collated": "true",
"items":{
"type": "string"
}
},
"sorted-name-length-pairs":{
"type": "array",
"description": "Objects composed of length and name of a sequence digested and ordered lexicographically",
"collated": "false",
"items":{
"type": "string"
}
}
},
"required": [
"names",
"lengths",
"sequences"
],
"inherent":[
"names",
"lengths",
"sequences"
]
}
}
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package uk.ac.ebi.eva.evaseqcol.utils;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelOneEntity;
import uk.ac.ebi.eva.evaseqcol.entities.SeqColLevelTwoEntity;
import uk.ac.ebi.eva.evaseqcol.io.SeqColGenerator;

import java.io.IOException;
import java.util.List;
import java.util.Map;

Expand All @@ -19,6 +21,9 @@ class SeqColMapConverterTest {

private SeqColGenerator seqColGenerator = new SeqColGenerator();

@Value("${service.info.file.path}")
private String serviceInfoFilePath;

@Test
void setSeqColLevelOneMapConverterTest() {
SeqColLevelOneEntity levelOneEntity = seqColGenerator.generateLevelOneEntity();
Expand All @@ -44,4 +49,10 @@ void seqColLevelTwoMapConverterTest() {
assertNotNull(levelTwoMap.get("lengths"));
assertNotNull(levelTwoMap.get("names"));
}

@Test
void jsonToMapTest() throws IOException {
Map<String, Object> serviceInfoMap = SeqColMapConverter.jsonToMap(serviceInfoFilePath);
assertNotNull(serviceInfoMap);
}
}

0 comments on commit ad28ad8

Please sign in to comment.