Skip to content

Commit

Permalink
Merge pull request #52 from elixir-europe/mars-receipt-library
Browse files Browse the repository at this point in the history
Mars receipt library
  • Loading branch information
kdp-cloud authored Nov 5, 2024
2 parents 31c12a6 + 18dd217 commit 24e9b5b
Show file tree
Hide file tree
Showing 88 changed files with 1,500 additions and 950 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build-biosamples-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: repository-services/isajson-biosamples
context: repository-services
file: repository-services/isajson-biosamples/Dockerfile
push: false
tags: user/app:latest
tags: user/app:latest
5 changes: 3 additions & 2 deletions .github/workflows/build-ena-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: repository-services/isajson-ena
context: repository-services
file: repository-services/isajson-ena/Dockerfile
push: false
tags: user/app:latest
tags: user/app:latest
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ cython_debug/
# Test credentials
test_credentials.json

tmp/
### IntelliJ IDEA ###
.gradle/
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### VS Code ###
.vscode/

### tmp ###
tmp/
8 changes: 6 additions & 2 deletions repository-services/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
services:
isa_biosamples:
build: isajson-biosamples
build:
context: .
dockerfile: isajson-biosamples/Dockerfile
ports:
- "8032:8032"
restart: unless-stopped

isa_sra:
build: isajson-ena
build:
context: .
dockerfile: isajson-ena/Dockerfile
ports:
- "8042:8042"
restart: unless-stopped
Expand Down
11 changes: 9 additions & 2 deletions repository-services/isajson-biosamples/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ FROM gradle:jdk11 AS builder
WORKDIR /app

COPY . .

WORKDIR /app/receipt
RUN ./gradlew build
RUN ./gradlew publishToMavenLocal

WORKDIR /app/isajson-biosamples
RUN ./gradlew build -x test -x spotlessApply --info --stacktrace "-Dorg.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"

# Use a lightweight base image to run the jar file
FROM openjdk:11-jre-slim
WORKDIR /app

ARG JAR_FILE=/app/build/libs/*.jar
ARG JAR_FILE=/app/isajson-biosamples/build/libs/*.jar

# Copy the JAR file from the builder stage
COPY --from=builder ${JAR_FILE} app.jar

# Set the entry point for the application
ENTRYPOINT ["java", "-jar", "/app.jar"]
ENTRYPOINT ["java", "-jar", "app.jar"]

2 changes: 2 additions & 0 deletions repository-services/isajson-biosamples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dependencies {
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5'
implementation group: 'dom4j', name: 'dom4j', version: '1.6.1'

implementation group: 'com.elixir.biohackaton', name: 'mars-receipt', version: '0.0.1'

compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.http.MediaType.APPLICATION_XML_VALUE;

import com.elixir.biohackaton.ISAToSRA.biosamples.receipt.Receipt;
import com.elixir.biohackaton.ISAToSRA.biosamples.receipt.Receipt.Accession;
import com.elixir.biohackaton.ISAToSRA.biosamples.receipt.Receipt;
import com.elixir.biohackaton.ISAToSRA.biosamples.model.BiosampleAccessionsMap;
import com.elixir.biohackaton.ISAToSRA.biosamples.service.BioSamplesSubmitter;
import com.elixir.biohackaton.ISAToSRA.model.IsaJson;
import com.elixir.biohackaton.ISAToSRA.model.Study;
import com.elixir.biohackaton.ISAToSRA.biosamples.service.MarsReceiptService;
import com.elixir.biohackaton.ISAToSRA.receipt.isamodel.*;
import com.elixir.biohackaton.ISAToSRA.receipt.marsmodel.MarsReceipt;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;

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

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -27,45 +25,41 @@
public class BioSampleSubmissionController {
@Autowired private BioSamplesSubmitter bioSamplesSubmitter;
@Autowired private ObjectMapper objectMapper;
@Autowired private MarsReceiptService marsReceiptService;

@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "Ok"),
@ApiResponse(responseCode = "401", description = "Unauthorized"),
@ApiResponse(responseCode = "403", description = "Forbidden"),
@ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "408", description = "Request Timeout"),
@ApiResponse(responseCode = "415", description = "Unsupported media type")
})
value = {
@ApiResponse(responseCode = "200", description = "Ok"),
@ApiResponse(responseCode = "401", description = "Unauthorized"),
@ApiResponse(responseCode = "403", description = "Forbidden"),
@ApiResponse(responseCode = "400", description = "Bad request"),
@ApiResponse(responseCode = "408", description = "Request Timeout"),
@ApiResponse(responseCode = "415", description = "Unsupported media type")
})
@CrossOrigin(origins = "http://localhost:8000")
@PostMapping(
value = "/submit",
consumes = {APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE})
value = "/submit",
consumes = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE })
public String performSubmissionToBioSamplesAndEna(
@RequestBody final String submissionPayload,
@RequestParam(value = "webinjwt") String webinJwt)
throws Exception {
@RequestBody final String submissionPayload,
@RequestParam(value = "webinjwt") String webinJwt)
throws Exception {
String webinToken;

objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

if (webinJwt != null) {
webinToken = webinJwt;
} else {
throw new RuntimeException("Webin Authentication Token is not provided");
}

objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

final IsaJson isaJson = this.objectMapper.readValue(submissionPayload, IsaJson.class);
final List<Study> studies = getStudies(isaJson);

final Map<String, String> accessionsMap = this.bioSamplesSubmitter.createBioSamples(studies, webinToken);
final Receipt repositoryData = new Receipt();

repositoryData.setTargetRepository("biosamples");
repositoryData.setAccessions(accessionsMap.values().stream()
.map(value -> new Accession(value, null)).collect(Collectors.toList()));
final BiosampleAccessionsMap accessionsMap = this.bioSamplesSubmitter.createBioSamples(studies, webinToken);
final MarsReceipt marsReceipt = marsReceiptService.convertReceiptToMars(accessionsMap, isaJson);

return this.objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(repositoryData);
return marsReceiptService.convertMarsReceiptToJson(marsReceipt);
}

public List<Study> getStudies(final IsaJson isaJson) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"submittedDate",
"submittedVia"
})
public class Sample implements Comparable<Sample> {
public class BioSample implements Comparable<BioSample> {
protected String accession;
protected String name;

Expand All @@ -61,7 +61,7 @@ public class Sample implements Comparable<Sample> {
protected SortedSet<Publication> publications;
protected SubmittedViaType submittedVia;

protected Sample() {}
protected BioSample() {}

@JsonProperty("accession")
public String getAccession() {
Expand Down Expand Up @@ -228,10 +228,10 @@ public SubmittedViaType getSubmittedVia() {
public boolean equals(Object o) {

if (o == this) return true;
if (!(o instanceof Sample)) {
if (!(o instanceof BioSample)) {
return false;
}
Sample other = (Sample) o;
BioSample other = (BioSample) o;

// dont use update date for comparisons, too volatile. SubmittedVia doesnt contain information
// for comparison
Expand All @@ -251,7 +251,7 @@ public boolean equals(Object o) {
}

@Override
public int compareTo(Sample other) {
public int compareTo(BioSample other) {
if (other == null) {
return 1;
}
Expand Down Expand Up @@ -413,7 +413,7 @@ public String toString() {
return sb.toString();
}

public static Sample build(
public static BioSample build(
String name,
String accession,
String domain,
Expand Down Expand Up @@ -447,7 +447,7 @@ public static Sample build(
null);
}

public static Sample build(
public static BioSample build(
String name,
String accession,
String domain,
Expand Down Expand Up @@ -484,7 +484,7 @@ public static Sample build(

// Used for deserializtion (JSON -> Java)
@JsonCreator
public static Sample build(
public static BioSample build(
@JsonProperty("name") String name,
@JsonProperty("accession") String accession,
@JsonProperty("domain") String domain,
Expand All @@ -509,7 +509,7 @@ public static Sample build(
@JsonProperty("publications") Collection<Publication> publications,
@JsonProperty("submittedVia") SubmittedViaType submittedVia) {

Sample sample = new Sample();
BioSample sample = new BioSample();

if (accession != null) {
sample.accession = accession.trim();
Expand Down Expand Up @@ -890,8 +890,8 @@ public Builder withNoPublications() {
return this;
}

public Sample build() {
return Sample.build(
public BioSample build() {
return BioSample.build(
name,
accession,
domain,
Expand Down Expand Up @@ -931,7 +931,7 @@ private ZonedDateTime parseDateTime(String datetimeString) {
* @param sample the sample to use as reference
* @return the Builder
*/
public static Builder fromSample(Sample sample) {
public static Builder fromSample(BioSample sample) {
return new Builder(sample.getName(), sample.getAccession())
.withDomain(sample.getDomain())
.withWebinSubmissionAccountId(sample.getWebinSubmissionAccountId())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.elixir.biohackaton.ISAToSRA.biosamples.model;

import com.elixir.biohackaton.ISAToSRA.receipt.ReceiptAccessionsMap;

public class BiosampleAccessionsMap {
public ReceiptAccessionsMap sourceAccessionsMap = new ReceiptAccessionsMap();
public ReceiptAccessionsMap studyAccessionsMap = new ReceiptAccessionsMap();
public ReceiptAccessionsMap sampleAccessionsMap = new ReceiptAccessionsMap();
}

This file was deleted.

Loading

0 comments on commit 24e9b5b

Please sign in to comment.