Skip to content

Commit

Permalink
Allow a mock Directory.
Browse files Browse the repository at this point in the history
Useful if you want to try things out but don't have a Directory login.
  • Loading branch information
Croft committed May 14, 2024
1 parent b130c61 commit 74d7279
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,20 @@ We recommend using Docker for running Directory sync.

First, you will need to set up the environment variables for this:

|Variable |Purpose |Default if not specified |
|:---------------------------------|:-----------------------------------------------------|:---------------------------------|
|DS_DIRECTORY_URL |Base URL of the Directory |https://directory.bbmri-eric.eu |
|DS_DIRECTORY_USER_NAME |User name for logging in to Directory | |
|DS_DIRECTORY_USER_PASS |Password for logging in to Directory | |
|DS_DIRECTORY_DEFAULT_COLLECTION_ID|ID of collection to be used if not in samples | |
|DS_DIRECTORY_MIN_DONORS |Minimum number of donors per star model hypercube |10 |
|DS_DIRECTORY_MAX_FACTS |Max number of star model hypercubes to be generated | |
|DS_DIRECTORY_ALLOW_STAR_MODEL |Set to 'True' to send star model info to Directory |False |
|DS_FHIR_STORE_URL |URL for FHIR store |http://bridgehead-bbmri-blaze:8080|
|DS_TIMER_CRON |Execution interval for Directory sync, cron format | |
|DS_RETRY_MAX |Maximum number of retries when sync fails |10 |
|DS_RETRY_INTERVAL |Interval between retries (seconds) |20 seconds |
| Variable | Purpose |Default if not specified |
|:-----------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------|
| DS_DIRECTORY_URL | Base URL of the Directory |https://directory.bbmri-eric.eu |
| DS_DIRECTORY_USER_NAME | User name for logging in to Directory | |
| DS_DIRECTORY_USER_PASS | Password for logging in to Directory | |
| DS_DIRECTORY_DEFAULT_COLLECTION_ID | ID of collection to be used if not in samples | |
| DS_DIRECTORY_MIN_DONORS | Minimum number of donors per star model hypercube |10 |
| DS_DIRECTORY_MAX_FACTS | Max number of star model hypercubes to be generated | |
| DS_DIRECTORY_ALLOW_STAR_MODEL | Set to 'True' to send star model info to Directory |False |
| DS_DIRECTORY_MOCK | Set to 'True' mock a Directory. In this mode, directory-sync will not contact the Directory. All Directory-related methods will simply return plausible fake values. |False |
| DS_FHIR_STORE_URL | URL for FHIR store |http://bridgehead-bbmri-blaze:8080|
| DS_TIMER_CRON | Execution interval for Directory sync, cron format | |
| DS_RETRY_MAX | Maximum number of retries when sync fails |10 |
| DS_RETRY_INTERVAL | Interval between retries (seconds) |20 seconds |

DS_DIRECTORY_USER_NAME and DS_DIRECTORY_USER_PASS are mandatory. If you do not specify these,
Directory sync will not run. Contact [Directory admin]([email protected]) to get login credentials.
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>de.samply</groupId>
<artifactId>directory_sync_service</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<name>directory_sync_service</name>
<description>Directory sync</description>
<url>https://github.com/samply/directory_sync_service</url>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>de.samply</groupId>
<artifactId>directory-sync</artifactId>
<version>0.3.1</version>
<version>0.3.2</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ public class Configuration {

@Value("${ds.directory.max_facts}")
private String directoryMaxFacts;

@Value("${ds.directory.mock}")
private String directoryMock;
}
20 changes: 9 additions & 11 deletions src/main/java/de/samply/directory_sync_service/DirectorySync.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.IRestfulClientFactory;
import ca.uhn.fhir.rest.client.impl.RestfulClientFactory;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
import de.samply.directory_sync.Sync;
import de.samply.directory_sync.directory.DirectoryApi;
Expand All @@ -18,9 +16,7 @@
import org.hl7.fhir.r4.model.OperationOutcome;

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

/**
* This class sets up connections to the FHIR store and to the Directory and
Expand Down Expand Up @@ -68,10 +64,11 @@ private boolean syncWithDirectory(Configuration configuration) {
boolean directoryAllowStarModel = Boolean.parseBoolean(configuration.getDirectoryAllowStarModel());
int directoryMinDonors = Integer.parseInt(configuration.getDirectoryMinDonors());
int directoryMaxFacts = Integer.parseInt(configuration.getDirectoryMaxFacts());
boolean directoryMock = Boolean.parseBoolean(configuration.getDirectoryMock());

DirectoryApi directoryApi = null;
try {
Either<OperationOutcome, DirectoryApi> directoryApiContainer = createDirectoryApi(directoryUserName, directoryUserPass, directoryUrl);
Either<OperationOutcome, DirectoryApi> directoryApiContainer = createDirectoryApi(directoryUserName, directoryUserPass, directoryUrl, directoryMock);
if (directoryApiContainer.isLeft()) {
logger.error("__________ syncWithDirectory: problem setting up Directory API: " + getErrorMessageFromOperationOutcome(directoryApiContainer.getLeft()));
return false;
Expand Down Expand Up @@ -147,19 +144,20 @@ private String getErrorMessageFromOperationOutcome(OperationOutcome operationOut

/**
* Opens a connection to the Directory API.
*
* <p>
* This is where the login to the Directory happens.
*
* @param directoryUserName User name for logging in to Directory
* @param directoryPassCode Password for logging in to Directory
* @param directoryUrl Base URL of the Directory
* @param directoryUserName User name for logging in to Directory
* @param directoryPassCode Password for logging in to Directory
* @param directoryUrl Base URL of the Directory
* @param directoryMock
* @return
* @throws IOException
*/
private Either<OperationOutcome, DirectoryApi> createDirectoryApi(String directoryUserName, String directoryPassCode, String directoryUrl)
private Either<OperationOutcome, DirectoryApi> createDirectoryApi(String directoryUserName, String directoryPassCode, String directoryUrl, boolean directoryMock)
throws IOException {
CloseableHttpClient client = HttpClients.createDefault();
return DirectoryApi.createWithLogin(client, directoryUrl, directoryUserName, directoryPassCode);
return DirectoryApi.createWithLogin(client, directoryUrl, directoryUserName, directoryPassCode, directoryMock);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ ds:
allow_star_model: "False"
min_donors: "10"
max_facts: "-1"
mock: "False"


0 comments on commit 74d7279

Please sign in to comment.