From d7be2b62dd49208e0365e595842079dcc5c37ef3 Mon Sep 17 00:00:00 2001 From: Shiva Rakshith Date: Mon, 17 Oct 2022 10:51:15 +0530 Subject: [PATCH 1/3] feat: update hcx integrator variables configuration --- .../io/hcxprotocol/dto/HCXIntegrator.java | 28 +++++++--- .../src/main/resources/application.conf | 9 --- .../io/hcxprotocol/dto/HCXIntegratorTest.java | 55 +++++++++++++++++++ 3 files changed, 75 insertions(+), 17 deletions(-) delete mode 100644 integration-sdks/hcx-integrator-sdk/src/main/resources/application.conf create mode 100644 integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java diff --git a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java index 24222068d..feb14d050 100644 --- a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java +++ b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java @@ -3,6 +3,8 @@ import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; +import java.util.Map; + /** * The methods and variables to access the configuration. Enumeration of error codes and operations. */ @@ -10,6 +12,8 @@ public class HCXIntegrator { private static HCXIntegrator hcxIntegrator = null; + private static Config config = null; + private HCXIntegrator() { } @@ -19,34 +23,42 @@ public static HCXIntegrator getInstance() { return hcxIntegrator; } - Config config = ConfigFactory.load(); + // To initialize config factory by passing the configuration as Map + public static void init(Map configMap) { + config = ConfigFactory.parseMap(configMap); + } + + // To initialize config factory by passing the configuration as String + public static void init(String configStr) { + config = ConfigFactory.parseString(configStr); + } public String getHCXProtocolBasePath() { - return config.getString("hcx.protocolBasePath"); + return config.getString("protocolBasePath"); } public String getParticipantCode() { - return config.getString("hcx.participantCode"); + return config.getString("participantCode"); } public String getAuthBasePath() { - return config.getString("hcx.authBasePath"); + return config.getString("authBasePath"); } public String getUsername() { - return config.getString("hcx.username"); + return config.getString("username"); } public String getPassword() { - return config.getString("hcx.password"); + return config.getString("password"); } public String getPrivateKey() { - return config.getString("hcx.encryptionPrivateKey"); + return config.getString("encryptionPrivateKey"); } public String getIGUrl() { - return config.getString("hcx.igUrl"); + return config.getString("igUrl"); } } diff --git a/integration-sdks/hcx-integrator-sdk/src/main/resources/application.conf b/integration-sdks/hcx-integrator-sdk/src/main/resources/application.conf deleted file mode 100644 index 466d2a13a..000000000 --- a/integration-sdks/hcx-integrator-sdk/src/main/resources/application.conf +++ /dev/null @@ -1,9 +0,0 @@ -hcx { - protocolBasePath = "", - authBasePath = "", - username = "", - password = "", - encryptionPrivateKey = "", - igUrl = "", - participantCode = "" -} \ No newline at end of file diff --git a/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java b/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java new file mode 100644 index 000000000..0075a16c8 --- /dev/null +++ b/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java @@ -0,0 +1,55 @@ +package io.hcxprotocol.dto; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class HCXIntegratorTest { + + @Test + public void testInitializeConfigMap() { + Map configMap = new HashMap<>(); + configMap.put("protocolBasePath", "http://localhost:8095"); + configMap.put("participantCode", "participant@01"); + configMap.put("authBasePath", "http://localhost:8080"); + configMap.put("username", "participant@gmail.com"); + configMap.put("password", "12345"); + configMap.put("encryptionPrivateKey", "Mz-VPPyU4RlcuYv1IwIvzw"); + configMap.put("igUrl", "http://localhost:8090"); + + HCXIntegrator.init(configMap); + HCXIntegrator hcxIntegrator = HCXIntegrator.getInstance(); + + assertEquals("http://localhost:8095", hcxIntegrator.getHCXProtocolBasePath()); + assertEquals("participant@01", hcxIntegrator.getParticipantCode()); + assertEquals("http://localhost:8080", hcxIntegrator.getAuthBasePath()); + assertEquals("participant@gmail.com", hcxIntegrator.getUsername()); + assertEquals("12345", hcxIntegrator.getPassword()); + assertEquals("Mz-VPPyU4RlcuYv1IwIvzw", hcxIntegrator.getPrivateKey()); + assertEquals("http://localhost:8090", hcxIntegrator.getIGUrl()); + + configMap.put("password", "67890"); + HCXIntegrator.init(configMap); + + assertEquals("67890", hcxIntegrator.getPassword()); + } + + @Test + public void testInitializeConfigString() { + String configStr = "{\"password\":\"12345\",\"protocolBasePath\":\"http://localhost:8095\",\"igUrl\":\"http://localhost:8090\",\"authBasePath\":\"http://localhost:8080\",\"encryptionPrivateKey\":\"Mz-VPPyU4RlcuYv1IwIvzw\",\"participantCode\":\"participant@01\",\"username\":\"participant@gmail.com\"}"; + + HCXIntegrator.init(configStr); + HCXIntegrator hcxIntegrator = HCXIntegrator.getInstance(); + + assertEquals("http://localhost:8095", hcxIntegrator.getHCXProtocolBasePath()); + assertEquals("participant@01", hcxIntegrator.getParticipantCode()); + assertEquals("http://localhost:8080", hcxIntegrator.getAuthBasePath()); + assertEquals("participant@gmail.com", hcxIntegrator.getUsername()); + assertEquals("12345", hcxIntegrator.getPassword()); + assertEquals("Mz-VPPyU4RlcuYv1IwIvzw", hcxIntegrator.getPrivateKey()); + assertEquals("http://localhost:8090", hcxIntegrator.getIGUrl()); + } +} From cb000b77daa45d7ff8b5d4545460037d15e5dcfc Mon Sep 17 00:00:00 2001 From: Shiva Rakshith Date: Mon, 17 Oct 2022 11:06:20 +0530 Subject: [PATCH 2/3] feat: update hcx integrator variables configuration --- .../main/java/io/hcxprotocol/dto/HCXIntegrator.java | 6 ++++-- .../java/io/hcxprotocol/impl/HCXIncomingRequest.java | 3 +++ .../java/io/hcxprotocol/impl/HCXOutgoingRequest.java | 11 +++++++---- .../io/hcxprotocol/interfaces/OutgoingRequest.java | 2 +- .../src/main/java/io/hcxprotocol/utils/Utils.java | 4 ++-- .../java/io/hcxprotocol/dto/HCXIntegratorTest.java | 10 ++++++++-- 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java index feb14d050..16158ef61 100644 --- a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java +++ b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/dto/HCXIntegrator.java @@ -17,7 +17,9 @@ public class HCXIntegrator { private HCXIntegrator() { } - public static HCXIntegrator getInstance() { + public static HCXIntegrator getInstance() throws Exception { + if(config == null) + throw new Exception("Please initialize the configuration variables, in order to initialize the SDK"); if (hcxIntegrator == null) hcxIntegrator = new HCXIntegrator(); return hcxIntegrator; @@ -28,7 +30,7 @@ public static void init(Map configMap) { config = ConfigFactory.parseMap(configMap); } - // To initialize config factory by passing the configuration as String + // To initialize config factory by passing the configuration as JSON String public static void init(String configStr) { config = ConfigFactory.parseString(configStr); } diff --git a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXIncomingRequest.java b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXIncomingRequest.java index 0f777655a..f1d85e52e 100644 --- a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXIncomingRequest.java +++ b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXIncomingRequest.java @@ -41,6 +41,9 @@ public class HCXIncomingRequest extends FhirPayload implements IncomingRequest { private final HCXIntegrator hcxIntegrator = HCXIntegrator.getInstance(); + public HCXIncomingRequest() throws Exception { + } + @Override public boolean process(String jwePayload, Operations operation, Map output) { Map error = new HashMap<>(); diff --git a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXOutgoingRequest.java b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXOutgoingRequest.java index bc3648849..1ef9b5a2f 100644 --- a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXOutgoingRequest.java +++ b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/impl/HCXOutgoingRequest.java @@ -54,6 +54,9 @@ public class HCXOutgoingRequest extends FhirPayload implements OutgoingRequest { private final HCXIntegrator hcxIntegrator = HCXIntegrator.getInstance(); + public HCXOutgoingRequest() throws Exception { + } + @Override public boolean generate(String fhirPayload, Operations operation, String recipientCode, Map output){ return process(fhirPayload, operation, recipientCode, "", "", output); @@ -81,8 +84,8 @@ private boolean process(String fhirPayload, Operations operation, String recipie output.putAll(response); } return result; - } catch (JsonProcessingException ex) { - // TODO: JsonProcessingException is handled as domain processing error, we will be enhancing in next version. + } catch (Exception ex) { + // TODO: Exception is handled as domain processing error, we will be enhancing in next version. output.put(ErrorCodes.ERR_DOMAIN_PROCESSING.toString(), ex.getMessage()); return result; } @@ -133,9 +136,9 @@ public boolean encryptPayload(Map headers, String fhirPayload, Ma } } - // we are handling the JsonProcessingException in processFunction method + // we are handling the Exception in processFunction method @Override - public boolean initializeHCXCall(String jwePayload, Operations operation, Map response) throws JsonProcessingException { + public boolean initializeHCXCall(String jwePayload, Operations operation, Map response) throws Exception { Map headers = new HashMap<>(); headers.put(Constants.AUTHORIZATION, "Bearer " + Utils.generateToken()); HttpResponse hcxResponse = HttpUtils.post(hcxIntegrator.getHCXProtocolBasePath() + operation.getOperation(), headers, jwePayload); diff --git a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/interfaces/OutgoingRequest.java b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/interfaces/OutgoingRequest.java index bcf59d60d..0ddd49e27 100644 --- a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/interfaces/OutgoingRequest.java +++ b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/interfaces/OutgoingRequest.java @@ -212,6 +212,6 @@ public interface OutgoingRequest { * * @throws JsonProcessingException The exception throws when it is having issues in parsing the JSON object. */ - boolean initializeHCXCall(String jwePayload, Operations operation, Map response) throws JsonProcessingException; + boolean initializeHCXCall(String jwePayload, Operations operation, Map response) throws Exception; } diff --git a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/utils/Utils.java b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/utils/Utils.java index 6cdbe4a7f..048cb0ced 100644 --- a/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/utils/Utils.java +++ b/integration-sdks/hcx-integrator-sdk/src/main/java/io/hcxprotocol/utils/Utils.java @@ -20,7 +20,7 @@ public class Utils { // TODO: In the initial version we are not handling the token caching, it will be handled in the next version - public static String generateToken() throws JsonProcessingException { + public static String generateToken() throws Exception { Map headers = new HashMap<>(); headers.put("content-type", "application/x-www-form-urlencoded"); Map fields = new HashMap<>(); @@ -34,7 +34,7 @@ public static String generateToken() throws JsonProcessingException { return responseBody.get("access_token"); } - public static Map searchRegistry(Object participantCode) throws ServerException, JsonProcessingException { + public static Map searchRegistry(Object participantCode) throws Exception { String filter = "{\"filters\":{\"participant_code\":{\"eq\":\"" + participantCode + "\"}}}"; Map headers = new HashMap<>(); headers.put(Constants.AUTHORIZATION, "Bearer " + generateToken()); diff --git a/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java b/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java index 0075a16c8..583cc649b 100644 --- a/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java +++ b/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java @@ -10,7 +10,7 @@ public class HCXIntegratorTest { @Test - public void testInitializeConfigMap() { + public void testInitializeConfigMap() throws Exception { Map configMap = new HashMap<>(); configMap.put("protocolBasePath", "http://localhost:8095"); configMap.put("participantCode", "participant@01"); @@ -38,7 +38,7 @@ public void testInitializeConfigMap() { } @Test - public void testInitializeConfigString() { + public void testInitializeConfigString() throws Exception { String configStr = "{\"password\":\"12345\",\"protocolBasePath\":\"http://localhost:8095\",\"igUrl\":\"http://localhost:8090\",\"authBasePath\":\"http://localhost:8080\",\"encryptionPrivateKey\":\"Mz-VPPyU4RlcuYv1IwIvzw\",\"participantCode\":\"participant@01\",\"username\":\"participant@gmail.com\"}"; HCXIntegrator.init(configStr); @@ -52,4 +52,10 @@ public void testInitializeConfigString() { assertEquals("Mz-VPPyU4RlcuYv1IwIvzw", hcxIntegrator.getPrivateKey()); assertEquals("http://localhost:8090", hcxIntegrator.getIGUrl()); } + + @Test(expected = Exception.class) + public void testInitializeException() throws Exception { + HCXIntegrator hcxIntegrator = HCXIntegrator.getInstance(); + assertEquals("http://localhost:8095", hcxIntegrator.getHCXProtocolBasePath()); + } } From 60b7bf24483537a00dc746e2e1e73c30d6043010 Mon Sep 17 00:00:00 2001 From: Shiva Rakshith Date: Mon, 17 Oct 2022 11:15:00 +0530 Subject: [PATCH 3/3] feat: update hcx integrator variables configuration --- .../src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java b/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java index 583cc649b..db4f519d9 100644 --- a/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java +++ b/integration-sdks/hcx-integrator-sdk/src/test/java/io/hcxprotocol/dto/HCXIntegratorTest.java @@ -54,8 +54,7 @@ public void testInitializeConfigString() throws Exception { } @Test(expected = Exception.class) - public void testInitializeException() throws Exception { + public void testWithoutConfigVariablesInitialization() throws Exception { HCXIntegrator hcxIntegrator = HCXIntegrator.getInstance(); - assertEquals("http://localhost:8095", hcxIntegrator.getHCXProtocolBasePath()); } }