Skip to content

Commit

Permalink
Added option that just logs into Directory without further actions
Browse files Browse the repository at this point in the history
For testing purposes only.

Also removed a logging statement that caused problems in mock mode.
  • Loading branch information
DavidCroftDKFZ committed Sep 16, 2024
1 parent 6f4c5b7 commit c2f955c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ First, you will need to set up the environment variables for this:
| 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_DIRECTORY_ONLY_LOGIN | Set to 'True' to log in to the Directory, without carrying out any further actions. | 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 |
Expand Down
2 changes: 1 addition & 1 deletion 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.4.6</version>
<version>1.4.7</version>
<name>directory_sync_service</name>
<description>Directory sync</description>
<url>https://github.com/samply/directory_sync_service</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,15 @@ public class DirectoryApi {
public DirectoryApi(String baseUrl, boolean mockDirectory, String username, String password) {
this.mockDirectory = mockDirectory;
this.directoryRest = new DirectoryRest(baseUrl, username, password);
if (!mockDirectory)
// Log in if we are not in mock mode
this.directoryRest.login();
relogin();
}

/**
* Log back in to the Directory. This is typically used in situations where there has
* been a long pause since the last API call to the Directory. It returns a fresh
* DirectoryApi object, which you should use to replace the existing one.
* <p>
* Returns null if something goes wrong.
*
* @return new DirectoryApi object.
* been a long pause since the last API call to the Directory.
*/
public void relogin() {
logger.info("login: logging back in");
logger.info("login: logging in");

if (mockDirectory)
// Don't try logging in if we are mocking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public static Optional<BbmriEricId> bbmriEricId(Organization collection) {
*/
public OperationOutcome updateResource(IBaseResource resource) {
logger.info("updateResource: @@@@@@@@@@ entered");
logger.info("updateResource: @@@@@@@@@@ theResource: " + ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resource));

// Remove the version ID, so that no If-Match header gets added to the request
// If you don't do this, Blaze will throw an exception like this:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public class Configuration {

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

@Value("${ds.directory.mock}")
private String directoryMock;

@Value("${ds.directory.only_login}")
private String directoryOnlyLogin;

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ public void execute(Configuration configuration) {
int directoryMinDonors = Integer.parseInt(configuration.getDirectoryMinDonors());
int directoryMaxFacts = Integer.parseInt(configuration.getDirectoryMaxFacts());
boolean directoryMock = Boolean.parseBoolean(configuration.getDirectoryMock());
boolean directoryOnlyLogin = Boolean.parseBoolean(configuration.getDirectoryOnlyLogin());

Sync.syncWithDirectoryFailover(retryMax, retryInterval, fhirStoreUrl, directoryUrl, directoryUserName, directoryUserPass, directoryDefaultCollectionId, directoryAllowStarModel, directoryMinDonors, directoryMaxFacts, directoryMock);
Sync.syncWithDirectoryFailover(retryMax, retryInterval, fhirStoreUrl, directoryUrl, directoryUserName, directoryUserPass, directoryDefaultCollectionId, directoryAllowStarModel, directoryMinDonors, directoryMaxFacts, directoryMock, directoryOnlyLogin);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class DiagnosisCorrections {
* * Retrieves diagnoses from the FHIR store for specimens with identifiable collections and their associated patients.
* * Converts raw ICD-10 codes into MIRIAM-compatible codes.
* * Collects corrected diagnosis codes from the Directory API based on the MIRIAM-compatible codes.
*
* <p>
* @param fhirApi
* @param directoryApi
* @param defaultCollectionId Default collection ID. May be null.
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/de/samply/directory_sync_service/sync/Sync.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class Sync {
*
* @throws IOException
*/
public static void syncWithDirectoryFailover(String retryMax, String retryInterval, String fhirStoreUrl, String directoryUrl, String directoryUserName, String directoryUserPass, String directoryDefaultCollectionId, boolean directoryAllowStarModel, int directoryMinDonors, int directoryMaxFacts, boolean directoryMock) {
public static void syncWithDirectoryFailover(String retryMax, String retryInterval, String fhirStoreUrl, String directoryUrl, String directoryUserName, String directoryUserPass, String directoryDefaultCollectionId, boolean directoryAllowStarModel, int directoryMinDonors, int directoryMaxFacts, boolean directoryMock, boolean directoryOnlyLogin) {
for (int retryNum = 0; retryNum < Integer.parseInt(retryMax); retryNum++) {
if (retryNum > 0) {
try {
Expand All @@ -47,17 +47,23 @@ public static void syncWithDirectoryFailover(String retryMax, String retryInterv
}
logger.info("syncWithDirectoryFailover: retrying sync, attempt " + retryNum + " of " + retryMax);
}
if (syncWithDirectory(retryMax, retryInterval, fhirStoreUrl, directoryUrl, directoryUserName, directoryUserPass, directoryDefaultCollectionId, directoryAllowStarModel, directoryMinDonors, directoryMaxFacts, directoryMock))
if (syncWithDirectory(fhirStoreUrl, directoryUrl, directoryUserName, directoryUserPass, directoryDefaultCollectionId, directoryAllowStarModel, directoryMinDonors, directoryMaxFacts, directoryMock, directoryOnlyLogin))
break;
}
}

private static boolean syncWithDirectory(String retryMax, String retryInterval, String fhirStoreUrl, String directoryUrl, String directoryUserName, String directoryUserPass, String directoryDefaultCollectionId, boolean directoryAllowStarModel, int directoryMinDonors, int directoryMaxFacts, boolean directoryMock) {
private static boolean syncWithDirectory(String fhirStoreUrl, String directoryUrl, String directoryUserName, String directoryUserPass, String directoryDefaultCollectionId, boolean directoryAllowStarModel, int directoryMinDonors, int directoryMaxFacts, boolean directoryMock, boolean directoryOnlyLogin) {
Map<String, String> correctedDiagnoses = null;
// Re-initialize helper classes every time this method gets called
FhirApi fhirApi = new FhirApi(fhirStoreUrl);
DirectoryApi directoryApi = new DirectoryApi(directoryUrl, directoryMock, directoryUserName, directoryUserPass);

// Login test. Don't perform any further actions on the Directory.
if (directoryOnlyLogin) {
logger.info(">>>>>>>>>>>>>>> syncWithDirectory: login was successful, now quitting because onlyLogin was set to true");
return true;
}

correctedDiagnoses = DiagnosisCorrections.generateDiagnosisCorrections(fhirApi, directoryApi, directoryDefaultCollectionId);
if (correctedDiagnoses == null) {
logger.warn("syncWithDirectory: there was a problem during diagnosis corrections");
Expand All @@ -78,7 +84,7 @@ private static boolean syncWithDirectory(String retryMax, String retryInterval,
return false;
}

logger.info("__________ syncWithDirectory: all synchronization tasks finished");
logger.info(">>>>>>>>>>>>>>> syncWithDirectory: all synchronization tasks finished");
return true;
}
}
3 changes: 1 addition & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ ds:
min_donors: "10"
max_facts: "-1"
mock: "False"


only_login: "False"

0 comments on commit c2f955c

Please sign in to comment.