Skip to content

Commit

Permalink
add evolution plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ewingrj committed Jul 6, 2020
1 parent 261cc4c commit 8598dff
Show file tree
Hide file tree
Showing 17 changed files with 712 additions and 24 deletions.
8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ buildscript {
apply plugin: "application"
apply plugin: "org.biocode.fims-web"

if (!project.hasProperty('fimsEvolutionVersion')) {
ext.fimsEvolutionVersion = "1.0.2"
}

fims {
maven {
username mavenUser
Expand Down Expand Up @@ -57,6 +53,7 @@ dependencies {
compile 'com.ibm.icu:icu4j:3.4.4'

compile group: 'org.parboiled', name: 'parboiled-java', version: '1.1.8'
compile group: 'com.auth0', name: 'java-jwt', version: '3.8.1'

compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.8.11'
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names', version: '2.9.6'
Expand All @@ -80,7 +77,7 @@ dependencies {
// https://mvnrepository.com/artifact/org.apache.commons/commons-text
compile group: 'org.apache.commons', name: 'commons-text', version: '1.4'
compile 'org.apache.commons:commons-lang3:3.8'
/compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.2'

compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.11'
compile group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.2.11'
Expand Down Expand Up @@ -109,7 +106,6 @@ dependencies {
compile 'commons-cli:commons-cli:1.4'

compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
compile composite.resolveDependency("org.biocode:biocode-fims-evolution:${fimsEvolutionVersion}", ":biocode-fims-evolution")

additionalSources(group: 'org.springframework.data', name: 'spring-data-commons', version: '1.10.1.RELEASE', classifier: 'sources') {
transitive = false
Expand Down
6 changes: 6 additions & 0 deletions geome-db.template
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ ezidpass = pass
mailUser = [email protected]
mailFrom = [email protected]
mailPassword = mypassword



############ evolution fims #############
# The url of the Evolution API
evolutionApi=http://localhost:3030
5 changes: 0 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ rootProject.name = 'geome-db'
if (hasProperty("gradleFimsDir") && file(gradleFimsDir).exists()) {
includeBuild gradleFimsDir
}

if (hasProperty("biocodeFimsEvolutionDir")) {
include ":biocode-fims-evolution"
project(":biocode-fims-evolution").projectDir = file(biocodeFimsEvolutionDir)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import biocode.fims.ncbi.sra.submission.SubmissionReporter;
import biocode.fims.ncbi.sra.submission.SubmissionTaskExecuter;
import biocode.fims.photos.BulkPhotoLoader;
import biocode.fims.plugins.evolution.application.config.EvolutionAppConfig;
import biocode.fims.records.FimsRowMapper;
import biocode.fims.records.GenericRecord;
import biocode.fims.records.GenericRecordRowMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package biocode.fims.plugins.evolution.application.config;

import biocode.fims.application.config.FimsProperties;
import biocode.fims.plugins.evolution.processing.EvolutionTaskExecutor;
import biocode.fims.plugins.evolution.run.EvolutionDatasetAction;
import biocode.fims.plugins.evolution.service.EvolutionService;
import biocode.fims.repositories.EntityIdentifierRepository;
import biocode.fims.repositories.RecordRepository;
import biocode.fims.service.ExpeditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

import javax.ws.rs.client.ClientBuilder;
import java.util.concurrent.Executors;

/**
* Configuration class for biocode-fims-evolution application.
*/
@Configuration
@PropertySource(value = "classpath:biocode-fims-evolution.props", ignoreResourceNotFound = true)
@Import({EvolutionProperties.class})
public class EvolutionAppConfig {
@Autowired
FimsProperties fimsProperties;
@Autowired
EvolutionProperties evolutionProperties;

@Autowired
RecordRepository recordRepository;
@Autowired
EntityIdentifierRepository entityIdentifierRepository;
@Autowired
ExpeditionService expeditionService;

@Bean
public EvolutionService evolutionService() {
return new EvolutionService(ClientBuilder.newClient(), evolutionProperties);
}

@Bean
public EvolutionTaskExecutor evolutionTaskExecutor() {
return new EvolutionTaskExecutor(Executors.newFixedThreadPool(1));
}

public EvolutionDatasetAction evolutionDatasetAction() {
return new EvolutionDatasetAction(recordRepository, evolutionService(), expeditionService, evolutionTaskExecutor(), entityIdentifierRepository, evolutionProperties, fimsProperties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package biocode.fims.plugins.evolution.application.config;

import biocode.fims.fimsExceptions.FimsRuntimeException;
import org.postgresql.util.Base64;
import org.springframework.core.env.Environment;

import java.security.KeyFactory;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;

/**
* @author rjewing
*/
public class EvolutionProperties {
private final Environment env;

public EvolutionProperties(Environment env) {
this.env = env;
}

public String api() {
return env.getRequiredProperty("evolutionApi");
}

public String resolverEndpoint() {
String url = env.getRequiredProperty("evolutionRecordResolverEndpoint");

if (!url.endsWith("/")) {
url += "/";
}

return url;
}

public String clientId() {
return env.getRequiredProperty("evolutionClientID");
}

public ECPrivateKey clientSK() {
String pemKey = env.getRequiredProperty("evolutionClientSK");

try {
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.decode(pemKey));
KeyFactory kf = KeyFactory.getInstance("EC");
return (ECPrivateKey) kf.generatePrivate(keySpec);
} catch (Exception e) {
throw new FimsRuntimeException("Failed to load evolutionClientSK", 500, e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package biocode.fims.plugins.evolution.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.Map;

/**
* @author rjewing
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class EvolutionRecord {
public String guid;
public String url;
public Map<String, Object> data;
public String recordDependency;
public String eventId;
public String userId;

public EvolutionRecord(String guid, String url, String recordDependency, Map<String, Object> data, String eventId, String userId) {
this.guid = guid;
this.url = url;
this.recordDependency = recordDependency;
this.data = data;
this.eventId = eventId;
this.userId = userId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package biocode.fims.plugins.evolution.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;

/**
* @author rjewing
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class EvolutionRecordReference {
public String recordGuid;
public String eventId;
public String userId;

public EvolutionRecordReference(String recordGuid, String eventId, String userId) {
this.recordGuid = recordGuid;
this.eventId = eventId;
this.userId = userId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package biocode.fims.plugins.evolution.processing;

import biocode.fims.plugins.evolution.models.EvolutionRecordReference;
import biocode.fims.plugins.evolution.service.EvolutionService;
import org.apache.commons.collections4.ListUtils;

import java.util.List;


/**
* @author rjewing
*/
public class EvolutionDiscoveryTask implements Runnable {

private final EvolutionService evolutionService;
private final List<EvolutionRecordReference> references;

public EvolutionDiscoveryTask(EvolutionService evolutionService, List<EvolutionRecordReference> references) {
this.evolutionService = evolutionService;
this.references = references;
}

@Override
public void run() {
ListUtils.partition(references, 10000).forEach(evolutionService::discovery);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package biocode.fims.plugins.evolution.processing;

import biocode.fims.plugins.evolution.models.EvolutionRecordReference;
import biocode.fims.plugins.evolution.service.EvolutionService;
import org.apache.commons.collections4.ListUtils;

import java.util.List;

/**
* @author rjewing
*/
public class EvolutionRetrievalTask implements Runnable {

private final EvolutionService evolutionService;
private final List<EvolutionRecordReference> references;

public EvolutionRetrievalTask(EvolutionService evolutionService, List<EvolutionRecordReference> references) {
this.evolutionService = evolutionService;
this.references = references;
}

@Override
public void run() {
ListUtils.partition(references, 10000).forEach(evolutionService::retrieval);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package biocode.fims.plugins.evolution.processing;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutorService;

/**
* @author rjewing
*/
public class EvolutionTaskExecutor {
private static final Logger logger = LoggerFactory.getLogger(EvolutionTaskExecutor.class);

private ExecutorService executorService;

public EvolutionTaskExecutor(ExecutorService executorService) {
this.executorService = executorService;
}

// TODO maybe need to set a timeout? https://geowarin.github.io/completable-futures-with-spring-async.html
public void addTask(Runnable task) {
// CompletableFuture.runAsync(task, executorService)
// .whenComplete((v, err) -> {
// if (err != null) {
// logger.error(err.getMessage(), err);
// }
// TODO log the results here?
// });

}
}
Loading

0 comments on commit 8598dff

Please sign in to comment.