-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from DiSSCo/feature/init
init
- Loading branch information
Showing
34 changed files
with
1,539 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/eu/dissco/exportjob/DisscoExportJobApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package eu.dissco.exportjob; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan; | ||
|
||
@SpringBootApplication | ||
@ConfigurationPropertiesScan | ||
public class DisscoExportJobApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(DisscoExportJobApplication.class, args); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package eu.dissco.exportjob; | ||
|
||
public class Profiles { | ||
public static final String DOI_LIST = "doi_list"; | ||
|
||
private Profiles(){} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package eu.dissco.exportjob; | ||
|
||
import eu.dissco.exportjob.component.JobRequestComponent; | ||
import eu.dissco.exportjob.exceptions.FailedProcessingException; | ||
import eu.dissco.exportjob.service.AbstractExportJobService; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class ProjectRunner implements CommandLineRunner { | ||
|
||
private final AbstractExportJobService exportJobService; | ||
private final ConfigurableApplicationContext context; | ||
private final JobRequestComponent jobRequestComponent; | ||
|
||
@Override | ||
public void run(String... args) throws FailedProcessingException { | ||
var request = jobRequestComponent.getJobRequest(); | ||
exportJobService.handleMessage(request); | ||
context.close(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/eu/dissco/exportjob/component/JobRequestComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package eu.dissco.exportjob.component; | ||
|
||
import eu.dissco.exportjob.domain.JobRequest; | ||
import eu.dissco.exportjob.domain.JobStateEndpoint; | ||
import eu.dissco.exportjob.domain.SearchParam; | ||
import eu.dissco.exportjob.exceptions.FailedProcessingException; | ||
import eu.dissco.exportjob.properties.JobProperties; | ||
import eu.dissco.exportjob.web.ExporterBackendClient; | ||
import java.util.ArrayList; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class JobRequestComponent { | ||
|
||
private final JobProperties properties; | ||
private final ExporterBackendClient client; | ||
|
||
public JobRequest getJobRequest() throws FailedProcessingException { | ||
var searchParams = new ArrayList<SearchParam>(); | ||
if (properties.getInputFields().size() != properties.getInputValues().size()) { | ||
log.error("Mismatch between input fields and input values for searching"); | ||
client.updateJobState(properties.getJobId(), JobStateEndpoint.FAILED); | ||
throw new FailedProcessingException(); | ||
} | ||
for (int i = 0; i < properties.getInputFields().size(); i++) { | ||
searchParams.add(new SearchParam(properties.getInputFields().get(i), properties.getInputValues().get(i))); | ||
} | ||
log.info("Received {} job request with id {} and {} search parameters", properties.getTargetType(), properties.getJobId(), | ||
searchParams); | ||
return new JobRequest(searchParams, properties.getTargetType(), properties.getJobId()); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/eu/dissco/exportjob/configuration/ApplicationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package eu.dissco.exportjob.configuration; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class ApplicationConfiguration { | ||
|
||
@Bean | ||
public ObjectMapper objectMapper() { | ||
var mapper = new ObjectMapper().findAndRegisterModules(); | ||
mapper.setSerializationInclusion(Include.NON_NULL); | ||
return mapper; | ||
} | ||
|
||
@Bean | ||
public DateTimeFormatter formatter() { | ||
return DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(ZoneOffset.UTC); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/eu/dissco/exportjob/configuration/ElasticSearchConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package eu.dissco.exportjob.configuration; | ||
|
||
import eu.dissco.exportjob.properties.ElasticSearchProperties; | ||
|
||
|
||
import co.elastic.clients.elasticsearch.ElasticsearchClient; | ||
import co.elastic.clients.json.jackson.JacksonJsonpMapper; | ||
import co.elastic.clients.transport.ElasticsearchTransport; | ||
import co.elastic.clients.transport.rest_client.RestClientTransport; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.auth.AuthScope; | ||
import org.apache.http.auth.UsernamePasswordCredentials; | ||
import org.apache.http.impl.client.BasicCredentialsProvider; | ||
import org.elasticsearch.client.RestClient; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class ElasticSearchConfiguration { | ||
private final ElasticSearchProperties properties; | ||
private final ObjectMapper mapper; | ||
|
||
@Bean | ||
public ElasticsearchClient elasticsearchClient() { | ||
var credentialsProvider = new BasicCredentialsProvider(); | ||
credentialsProvider.setCredentials(AuthScope.ANY, | ||
new UsernamePasswordCredentials(properties.getUsername(), properties.getPassword())); | ||
RestClient restClient = RestClient.builder(new HttpHost(properties.getHostname(), | ||
properties.getPort())) | ||
.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder | ||
.setDefaultCredentialsProvider(credentialsProvider)).build(); | ||
ElasticsearchTransport transport = new RestClientTransport(restClient, | ||
new JacksonJsonpMapper(mapper)); | ||
return new ElasticsearchClient(transport); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/eu/dissco/exportjob/configuration/S3Configuration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package eu.dissco.exportjob.configuration; | ||
|
||
import eu.dissco.exportjob.properties.S3Properties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; | ||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.s3.S3AsyncClient; | ||
import software.amazon.awssdk.transfer.s3.S3TransferManager; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class S3Configuration { | ||
private final S3Properties s3Properties; | ||
|
||
@Bean | ||
public S3AsyncClient s3Client() { | ||
return S3AsyncClient.crtBuilder() | ||
.credentialsProvider(StaticCredentialsProvider.create( | ||
AwsBasicCredentials.create(s3Properties.getAccessKey(), | ||
s3Properties.getAccessSecret()))) | ||
.region(Region.EU_WEST_2) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public S3TransferManager transferManager() { | ||
return S3TransferManager.builder().s3Client(s3Client()).build(); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/eu/dissco/exportjob/configuration/WebClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package eu.dissco.exportjob.configuration; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.reactive.ReactorClientHttpConnector; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.netty.http.client.HttpClient; | ||
|
||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebClientConfiguration { | ||
|
||
@NotBlank | ||
@Value("${endpoint.backend}") | ||
private String backendEndpoint; | ||
|
||
@NotBlank | ||
@Value("${endpoint.token}") | ||
private String tokenEndpoint; | ||
|
||
@Bean(name= "exporterClient") | ||
public WebClient webClient(){ | ||
return WebClient.builder() | ||
.clientConnector(new ReactorClientHttpConnector(HttpClient.create())) | ||
.baseUrl(backendEndpoint) | ||
.defaultHeader(HttpHeaders.CONTENT_TYPE) | ||
.build(); | ||
} | ||
|
||
@Bean(name = "tokenClient") | ||
public WebClient tokenClient() { | ||
return WebClient.builder() | ||
.clientConnector(new ReactorClientHttpConnector(HttpClient.create())) | ||
.baseUrl(tokenEndpoint) | ||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) | ||
.build(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package eu.dissco.exportjob.domain; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public record JobRequest( | ||
List<SearchParam> searchParams, | ||
TargetType targetType, | ||
UUID jobId | ||
) { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/eu/dissco/exportjob/domain/JobStateEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package eu.dissco.exportjob.domain; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum JobStateEndpoint { | ||
FAILED("/failed"), | ||
RUNNING("/running"); | ||
|
||
private final String endpoint; | ||
JobStateEndpoint(String s){ | ||
this.endpoint = s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package eu.dissco.exportjob.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public enum JobType { | ||
@JsonProperty("doi_list") DOI_LIST | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package eu.dissco.exportjob.domain; | ||
|
||
public record SearchParam( | ||
String inputField, | ||
String inputValue | ||
) { | ||
|
||
} |
Oops, something went wrong.