-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
712 additions
and
24 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
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 |
---|---|---|
|
@@ -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 |
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
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
51 changes: 51 additions & 0 deletions
51
src/main/java/biocode/fims/plugins/evolution/application/config/EvolutionAppConfig.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,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); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/biocode/fims/plugins/evolution/application/config/EvolutionProperties.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,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); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/biocode/fims/plugins/evolution/models/EvolutionRecord.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,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; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/biocode/fims/plugins/evolution/models/EvolutionRecordReference.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,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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/biocode/fims/plugins/evolution/processing/EvolutionDiscoveryTask.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,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); | ||
} | ||
|
||
} | ||
|
28 changes: 28 additions & 0 deletions
28
src/main/java/biocode/fims/plugins/evolution/processing/EvolutionRetrievalTask.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,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); | ||
} | ||
|
||
} | ||
|
31 changes: 31 additions & 0 deletions
31
src/main/java/biocode/fims/plugins/evolution/processing/EvolutionTaskExecutor.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,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? | ||
// }); | ||
|
||
} | ||
} |
Oops, something went wrong.