-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(converter): add converter utils
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/hubsante/model/converter/ConverterUtils.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,35 @@ | ||
package com.hubsante.model.converter; | ||
|
||
import com.hubsante.model.cisu.CreateCaseWrapper; | ||
import com.hubsante.model.edxl.EdxlMessage; | ||
import com.hubsante.model.health.CreateCaseHealthWrapper; | ||
|
||
import static com.hubsante.model.config.Constants.HEALTH_PREFIX; | ||
|
||
public class ConverterUtils { | ||
|
||
public static boolean requiresCisuConversion(Boolean directCisuPreference, EdxlMessage edxlMessage) { | ||
return isPartOfCisuExchange(edxlMessage) && | ||
isCisuModel(edxlMessage) && | ||
!isDirectCisuForHealthActor(directCisuPreference); | ||
} | ||
|
||
public static boolean isPartOfCisuExchange(EdxlMessage edxlMessage) { | ||
String recipientID = getRecipientID(edxlMessage); | ||
String senderID = edxlMessage.getSenderID(); | ||
return !(recipientID.startsWith(HEALTH_PREFIX) && senderID.startsWith(HEALTH_PREFIX)); | ||
} | ||
|
||
public static boolean isCisuModel(EdxlMessage edxlMessage) { | ||
return edxlMessage.getFirstContentMessage() instanceof CreateCaseWrapper | ||
|| edxlMessage.getFirstContentMessage() instanceof CreateCaseHealthWrapper; | ||
} | ||
|
||
public static boolean isDirectCisuForHealthActor(Boolean directCisuPreference) { | ||
return directCisuPreference != null && directCisuPreference; | ||
} | ||
|
||
public static String getRecipientID(EdxlMessage edxlMessage) { | ||
return edxlMessage.getDescriptor().getExplicitAddress().getExplicitAddressValue(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/com/hubsante/model/converter/ConverterUtilsTest.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,67 @@ | ||
package com.hubsante.model.converter; | ||
|
||
import com.hubsante.model.EdxlHandler; | ||
import com.hubsante.model.TestMessagesHelper; | ||
import com.hubsante.model.builders.EDXL_DE_Builder; | ||
import com.hubsante.model.custom.CustomMessage; | ||
import com.hubsante.model.edxl.ContentMessage; | ||
import com.hubsante.model.edxl.EdxlMessage; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
|
||
public class ConverterUtilsTest { | ||
@ParameterizedTest | ||
@CsvSource({"true, true", "false, false", ", false"}) | ||
void testIsDirectCisuForHealthActor(Boolean directCisuPreference, boolean expectedDirectCisuForHealthActor) { | ||
assertEquals(expectedDirectCisuForHealthActor, ConverterUtils.isDirectCisuForHealthActor(directCisuPreference)); | ||
} | ||
|
||
@Test | ||
public void testGetRecipientID() { | ||
String DISTRIBUTION_ID = "id-12345"; | ||
String SENDER_ID = "sender-x"; | ||
String RECIPIENT_ID = "recipient-y"; | ||
ContentMessage contentMessage = new CustomMessage(); | ||
|
||
EdxlMessage message = new EDXL_DE_Builder(DISTRIBUTION_ID, SENDER_ID, RECIPIENT_ID) | ||
.contentMessage(contentMessage) | ||
.build(); | ||
|
||
assertEquals(RECIPIENT_ID, ConverterUtils.getRecipientID(message)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({"fr.health, fr.health, false", "fr.health, not.fr.health, true","not.health, fr.health, true", "not.health, not.fr.health, true"}) | ||
void testIsPartOfCisuExchange(String senderID, String recipientID, Boolean expectedPartOfCisu) { | ||
String DISTRIBUTION_ID = "id-12345"; | ||
ContentMessage contentMessage = new CustomMessage(); | ||
|
||
EdxlMessage message = new EDXL_DE_Builder(DISTRIBUTION_ID, senderID, recipientID) | ||
.contentMessage(contentMessage) | ||
.build(); | ||
|
||
assertEquals(expectedPartOfCisu, ConverterUtils.isPartOfCisuExchange(message)); | ||
} | ||
|
||
@Test | ||
public void testIsCisuModel() throws IOException { | ||
EdxlHandler converter = new EdxlHandler(); | ||
File jsonRCMessage = new File(TestMessagesHelper.class.getClassLoader().getResource("sample/valid/RC-EDA/RC-EDA.json").getFile()); | ||
String useRCCaseJson = new String(Files.readAllBytes(jsonRCMessage.toPath()), StandardCharsets.UTF_8); | ||
EdxlMessage RCMessage = converter.deserializeJsonEDXL(useRCCaseJson); | ||
assertTrue(ConverterUtils.isCisuModel(RCMessage)); | ||
|
||
// File jsonRSMessage = new File(TestMessagesHelper.class.getClassLoader().getResource("sample/examples/RS-EDA/RS-EDA-SMUR_FemmeEnceinte_DelphineVigneau.01.json").getFile()); | ||
// String useRSCaseJson = new String(Files.readAllBytes(jsonRSMessage.toPath()), StandardCharsets.UTF_8); | ||
// EdxlMessage RSMessage = converter.deserializeJsonEDXL(useRSCaseJson); | ||
// assertTrue(ConverterUtils.isCisuModel(RSMessage)); | ||
} | ||
} |