From c2f955cab8467f37c801c898d4337cde5aa64eb4 Mon Sep 17 00:00:00 2001 From: DavidCroftDKFZ <46788708+DavidCroftDKFZ@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:28:04 +0200 Subject: [PATCH] Added option that just logs into Directory without further actions For testing purposes only. Also removed a logging statement that caused problems in mock mode. --- README.md | 1 + pom.xml | 2 +- .../directory/DirectoryApi.java | 13 +++---------- .../directory_sync_service/fhir/FhirApi.java | 1 - .../service/Configuration.java | 6 +++++- .../service/DirectorySyncJob.java | 3 ++- .../sync/DiagnosisCorrections.java | 2 +- .../samply/directory_sync_service/sync/Sync.java | 14 ++++++++++---- src/main/resources/application.yml | 3 +-- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d32dcc5..3040a5a 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/pom.xml b/pom.xml index a1d3f51..9bc5536 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ de.samply directory_sync_service - 1.4.6 + 1.4.7 directory_sync_service Directory sync https://github.com/samply/directory_sync_service diff --git a/src/main/java/de/samply/directory_sync_service/directory/DirectoryApi.java b/src/main/java/de/samply/directory_sync_service/directory/DirectoryApi.java index 6f4f231..4b95a6b 100644 --- a/src/main/java/de/samply/directory_sync_service/directory/DirectoryApi.java +++ b/src/main/java/de/samply/directory_sync_service/directory/DirectoryApi.java @@ -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. - *

- * 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 diff --git a/src/main/java/de/samply/directory_sync_service/fhir/FhirApi.java b/src/main/java/de/samply/directory_sync_service/fhir/FhirApi.java index a858e56..9fc676c 100644 --- a/src/main/java/de/samply/directory_sync_service/fhir/FhirApi.java +++ b/src/main/java/de/samply/directory_sync_service/fhir/FhirApi.java @@ -97,7 +97,6 @@ public static Optional 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: diff --git a/src/main/java/de/samply/directory_sync_service/service/Configuration.java b/src/main/java/de/samply/directory_sync_service/service/Configuration.java index bb006f0..b9825db 100644 --- a/src/main/java/de/samply/directory_sync_service/service/Configuration.java +++ b/src/main/java/de/samply/directory_sync_service/service/Configuration.java @@ -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; + } diff --git a/src/main/java/de/samply/directory_sync_service/service/DirectorySyncJob.java b/src/main/java/de/samply/directory_sync_service/service/DirectorySyncJob.java index 1e94e0c..dbafc62 100644 --- a/src/main/java/de/samply/directory_sync_service/service/DirectorySyncJob.java +++ b/src/main/java/de/samply/directory_sync_service/service/DirectorySyncJob.java @@ -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); } /** diff --git a/src/main/java/de/samply/directory_sync_service/sync/DiagnosisCorrections.java b/src/main/java/de/samply/directory_sync_service/sync/DiagnosisCorrections.java index 6b3add2..ebf148a 100644 --- a/src/main/java/de/samply/directory_sync_service/sync/DiagnosisCorrections.java +++ b/src/main/java/de/samply/directory_sync_service/sync/DiagnosisCorrections.java @@ -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. - * + *

* @param fhirApi * @param directoryApi * @param defaultCollectionId Default collection ID. May be null. diff --git a/src/main/java/de/samply/directory_sync_service/sync/Sync.java b/src/main/java/de/samply/directory_sync_service/sync/Sync.java index 9c90580..a2011fd 100644 --- a/src/main/java/de/samply/directory_sync_service/sync/Sync.java +++ b/src/main/java/de/samply/directory_sync_service/sync/Sync.java @@ -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 { @@ -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 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"); @@ -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; } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b35d2e1..1cd0d2d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,5 +17,4 @@ ds: min_donors: "10" max_facts: "-1" mock: "False" - - + only_login: "False"