-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from bcgov/feature/bugfix/parser
Feature/bugfix/parser
- Loading branch information
Showing
12 changed files
with
626 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Contributing | ||
|
||
All Contributions to this repository start with a Jira Item associated with the work request. | ||
|
||
## Pull Request Process | ||
|
||
1. Fork the repository on you personal github space. see:[working with forks](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks). | ||
1. [Build](README.md#build) and run the application on your local environment. | ||
1. Commit your changes to your branch. | ||
1. Update the README.md with details of changes to the interface, this includes new environment | ||
variables, exposed ports, useful file locations and container parameters. | ||
1. When your change is ready to be reviewed, open a PR on this repository using our [Pull Request Template](.github/PULL_REQUEST_TEMPLATE) and optionally assign one or more reviewer. Also, in the comment of the Jira item, put a link to the Pull Request and move the item to `in review` | ||
1. If some changes are required, you will be notified in the PR, address any change requested and push to the same branch. | ||
1. When your change is meeting the requirement, the reviewer will merge the code into master, you can celebrate! | ||
|
||
## Open a new bug in jira | ||
|
||
- When a bug is detected in the application, a jira bug must be open | ||
the bug should be documented as followed: | ||
- Expected Behavior | ||
- Current Behavior | ||
- Steps to Reproduce | ||
- Environment | ||
- Description (stack traces, screenshot, error messages, splunk logs query) | ||
- Optionally you can suggest a possible solution | ||
- set the target release | ||
|
||
## Open a new feature request in jira | ||
|
||
- For feature enhancements, a jira task or story must be open | ||
- set the target release |
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
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
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,25 @@ | ||
package ca.bc.gov.iamp.bcparis; | ||
|
||
public class Keys { | ||
|
||
public static final String REQUEST_SCHEMA_FROM_KEY = "FROM"; | ||
public static final String REQUEST_SCHEMA_TO_KEY = "TO"; | ||
public static final String REQUEST_SCHEMA_TEXT_KEY = "TEXT"; | ||
public static final String REQUEST_SCHEMA_RE_KEY = "RE"; | ||
public static final String REQUEST_SCHEMA_SN_KEY = "SN"; | ||
public static final String REQUEST_SCHEMA_MT_KEY = "MT"; | ||
public static final String REQUEST_SCHEMA_MSID_KEY = "MSID"; | ||
public static final String REQUEST_SCHEMA_SUBJ_KEY = "SUBJ"; | ||
public static final String REQUEST_SCHEMA_SNME_KEY = "SNME"; | ||
public static final String REQUEST_SCHEMA_DL_KEY = "DL"; | ||
public static final String REQUEST_SCHEMA_LIC_KEY = "LIC"; | ||
public static final String REQUEST_SCHEMA_ODN_KEY = "ODN"; | ||
public static final String REQUEST_SCHEMA_FLC_KEY = "FLC"; | ||
public static final String REQUEST_SCHEMA_VIN_KEY = "VIN"; | ||
public static final String REQUEST_SCHEMA_REG_KEY = "REG"; | ||
public static final String REQUEST_SCHEMA_RNS_KEY = "RNS"; | ||
public static final String REQUEST_SCHEMA_RVL_KEY = "RVL"; | ||
// TODO: REMOVE TOKEN AFTER SATELLITE SERVICE IS DEPRECATED | ||
public static final String REQUEST_SCHEMA_TEST_RNS_KEY = "TestRNS"; | ||
|
||
} |
115 changes: 115 additions & 0 deletions
115
src/main/java/ca/bc/gov/iamp/bcparis/message/MessageUtils.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,115 @@ | ||
package ca.bc.gov.iamp.bcparis.message; | ||
|
||
import ca.bc.gov.iamp.bcparis.Keys; | ||
import org.springframework.util.StringUtils; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class MessageUtils { | ||
|
||
private static final String SEMICOLLON = ":"; | ||
private static final String STRING_END_ONE = "]]>$"; | ||
private static final String STRING_END_TWO = "\n$"; | ||
|
||
private static HashSet<String> KNOWN_TOKENS = new HashSet<String>() {{ | ||
add(Keys.REQUEST_SCHEMA_SN_KEY); | ||
add(Keys.REQUEST_SCHEMA_MT_KEY); | ||
add(Keys.REQUEST_SCHEMA_MSID_KEY); | ||
add(Keys.REQUEST_SCHEMA_FROM_KEY); | ||
add(Keys.REQUEST_SCHEMA_TO_KEY); | ||
add(Keys.REQUEST_SCHEMA_SUBJ_KEY); | ||
add(Keys.REQUEST_SCHEMA_TEXT_KEY); | ||
add(Keys.REQUEST_SCHEMA_RE_KEY); | ||
add(Keys.REQUEST_SCHEMA_SNME_KEY); | ||
add(Keys.REQUEST_SCHEMA_DL_KEY); | ||
add(Keys.REQUEST_SCHEMA_LIC_KEY); | ||
add(Keys.REQUEST_SCHEMA_ODN_KEY); | ||
add(Keys.REQUEST_SCHEMA_FLC_KEY); | ||
add(Keys.REQUEST_SCHEMA_VIN_KEY); | ||
add(Keys.REQUEST_SCHEMA_REG_KEY); | ||
add(Keys.REQUEST_SCHEMA_RNS_KEY); | ||
add(Keys.REQUEST_SCHEMA_RVL_KEY); | ||
add(Keys.REQUEST_SCHEMA_TEST_RNS_KEY); | ||
}}; | ||
|
||
|
||
/** | ||
* Extract the attribute value based on a give token | ||
* Known tokens includes: | ||
* <ul> | ||
* <li>FROM | ||
* <li>TO | ||
* <li>TEXT | ||
* <li>RE | ||
* <li>SN | ||
* <li>MT | ||
* <li>MSID | ||
* <li>SUBJ | ||
* <li>SNME | ||
* <li>DL | ||
* <li>LIC | ||
* <li>ODN | ||
* <li>FLC | ||
* <li>VIN | ||
* <li>REG | ||
* <li>RNS | ||
* <li>RVL | ||
* <li>TestRNS | ||
* </ul> | ||
* | ||
* @param message the source message | ||
* @param key a known key | ||
* @return the value of the attribute | ||
* @throws IllegalArgumentException if the key is not a known key | ||
* @since 1.0.20 | ||
*/ | ||
public static String GetValue(String message, String key) { | ||
|
||
if (!KNOWN_TOKENS.contains(key)) throw new IllegalArgumentException("key must be a known token"); | ||
|
||
if (StringUtils.isEmpty(message)) return null; | ||
|
||
message = removeKnownEnd(message); | ||
|
||
message = removeToToken(message, key); | ||
|
||
if (message == null) return null; | ||
|
||
return message.substring(0, getEndIndex(message)).replaceAll("\\s+$", ""); | ||
|
||
} | ||
|
||
private static String removeKnownEnd(String message) { | ||
message = message.replaceAll(STRING_END_ONE, ""); | ||
return message.replaceAll(STRING_END_TWO, ""); | ||
} | ||
|
||
private static String removeToToken(String message, String token) { | ||
int startIndex = message.indexOf(token + SEMICOLLON); | ||
if (startIndex == -1) return null; | ||
|
||
startIndex += token.length() + 1; | ||
|
||
return message.substring(startIndex); | ||
} | ||
|
||
private static int getEndIndex(String message) { | ||
int currentEndIndex = message.length(); | ||
|
||
for (String token : KNOWN_TOKENS) { | ||
|
||
int tokenIndex = message.indexOf(token + SEMICOLLON); | ||
|
||
if (tokenIndex < currentEndIndex && tokenIndex >= 0) { | ||
currentEndIndex = tokenIndex; | ||
} | ||
|
||
if (message.indexOf(":") > currentEndIndex) break; | ||
} | ||
|
||
return currentEndIndex; | ||
} | ||
} | ||
|
||
|
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
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
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
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,62 @@ | ||
package ca.bc.gov.iamp.bcparis; | ||
|
||
public class FakeCData { | ||
|
||
public static String SAMPLE_DRIVER_DL = "<![CDATA[SN:M00001-0001 MT:DUF MSID:BRKR-190515-20:02:07 FROM:BC41127 TO:BC41027 TEXT:DL:3559874\n]]>"; | ||
public static String SAMPLE_DRIVER_MULTIPLE_PARAMS = "<![CDATA[SN:M00001-0001 MT:DUF MSID:BRKR-190515-20:02:07 FROM:BC41127 TO:BC41027 TEXT:BCPARIS Diagnostic Test qwe20190827173834DL:3559874 SNME:NEWMAN/G1:OLDSON/G2:MIKE/DOB:19900214\n]]>"; | ||
public static String SAMPLE_DRIVER_SNME = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190515-20:05:48 FROM:BC41127TO:BC41027TEXT:RE: 0509\nHC BC40940\nBC41027\nSNME:NEWMAN/G1:OLDSON/G2:MIKE/DOB:19900214\n\n2019051520054820190515200548]]>"; | ||
public static String SAMPLE_INVALID_DRIVER = "<![CDATA[SN:M00001-0001 MT:DUF MSID:BRKR-190515-20:02:07 FROM:BC41127 TO:BC41027 TEXT:\n]]>"; | ||
public static String SAMPLE_INVALID_VEHICLE = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190515-20:02:04 FROM:BC41127 TO:BC41028 TEXT:RE: 8261\n" + | ||
"HC BC11422\n" + | ||
"BC41028\n" + | ||
"]]>"; | ||
public static String SAMPLE_POR = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190515-20:05:48 FROM:BC41127TO:BC41029TEXT:RE: 0509\nHC BC40940\nBC41027\nSNME:WISKIN/G1:TOMAS/G2:GEORGE/G3:ALPHONSE/DOB:20050505\n\n2019051520054820190515200548]]>"; | ||
public static String SAMPLE_SATELITTE = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190820-16:26:19\n" + | ||
"FROM:BC41127\n" + | ||
"TO:BC41027\n" + | ||
"TEXT:BCPARIS Diagnostic Test qwe20190820202619REG:2156746\n" + | ||
" \n" + | ||
"SNME:SMITH/G1:JOHN/\n" + | ||
" \n" + | ||
"2019082020261920190820202619\n" + | ||
"]]>"; | ||
public static String SAMPLE_SATELITTE_ROUND_TRIP = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190820-16:26:19\n" + | ||
"FROM:BC41127\n" + | ||
"TO:BC41127\n" + | ||
"TEXT:BCPARIS Diagnostic Test qwe20190820202619REG:2156746\n" + | ||
" \n" + | ||
"SNME:SMITH/G1:JOHN/\n" + | ||
" \n" + | ||
"2019082020261920190820202619\n" + | ||
"]]>"; | ||
public static String SAMPLE_VEHICLE_LIC = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190515-20:02:04 FROM:BC41127 TO:BC41028 TEXT:RE: 8261\n" + | ||
"HC BC11422 \n" + | ||
"BC41028 \n" + | ||
"LIC:PN890H\n" + | ||
"\n" + | ||
"2019051520020420190515200204\n" + | ||
"\n" + | ||
"]]>"; | ||
public static String SAMPLE_VEHICLE_MULTIPLE_PARAMS = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190515-20:09:47 FROM:BC41127 TO:BC41028 TEXT:BCPARIS Diagnostic Test qwe20190827173834\n" + | ||
"\n" + | ||
"LIC:233AWB/H/LIC:GVW143/H/LIC:007FJR/H/LIC:JXX477/REG:957167/VIN:1GNEL19W1XB163160/VIN:163160/P:Y/VIN:163160/P:Y/RSVP:16\n" + | ||
"\n" + | ||
"2019082717383420190827173834\n" + | ||
"\n" + | ||
"]]>"; | ||
public static String SAMPLE_VEHICLE_RNS = "<![CDATA[SN:M00001-0001 MT:DUF MSID:BRKR-190515-20:02:03 FROM:BC41127 TO:BC41028 SUBJ:AB5184 FOR ACCD ENTRY TEXT:\n" + | ||
"RNS:845513634081303/\n" + | ||
"]]>"; | ||
public static String SAMPLE_VEHICLE_RVL = "<![CDATA[SN:M00001-0001 MT:DUF MSID:BRKR-190515-20:02:03 FROM:BC41127 TO:BC41028 SUBJ:AB5184 FOR ACCD ENTRY TEXT:\n" + | ||
"RVL:845513634081303/\n" + | ||
"]]>"; | ||
public static String SAMPLE_VEHICLE_VIN = "<![CDATA[SN:M00001-0001 MT:MUF MSID:BRKR-190515-20:09:47 FROM:BC41127 TO:BC41028 TEXT:RE: 2505\n" + | ||
"HC BC93181 \n" + | ||
"BC41028 \n" + | ||
"VIN:1FTEW1EF3GKF29092\n" + | ||
"\n" + | ||
"2019051520094620190515200946\n" + | ||
"\n" + | ||
"]]>"; | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/test/java/ca/bc/gov/iamp/bcparis/message/MessageUtilsEdgeCaseGetValueTest.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,32 @@ | ||
package ca.bc.gov.iamp.bcparis.message; | ||
|
||
import ca.bc.gov.iamp.bcparis.Keys; | ||
import ca.bc.gov.iamp.bcparis.model.message.body.Body; | ||
import ca.bc.gov.iamp.bcparis.util.RegexTokenizer; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class MessageUtilsEdgeCaseGetValueTest { | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void WithTokenNotKnownTokenShouldThrowException() { | ||
MessageUtils.GetValue("A message", "token"); | ||
} | ||
|
||
|
||
@Test | ||
public void WithEmptyStringShouldReturnEmptyString() { | ||
String result = MessageUtils.GetValue("", Keys.REQUEST_SCHEMA_FROM_KEY); | ||
Assert.assertNull(result); | ||
} | ||
|
||
@Test | ||
public void WithNullStringShouldReturnNullString() { | ||
String result = MessageUtils.GetValue(null, Keys.REQUEST_SCHEMA_FROM_KEY); | ||
Assert.assertNull(result); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.