-
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.
Revert "Delete src/main/java/ca/bc/gov/iamp/bcparis/transformation/Me…
…ssageTransform.java" This reverts commit d42cb88.
- Loading branch information
1 parent
d42cb88
commit b2b7b60
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/ca/bc/gov/iamp/bcparis/transformation/MessageTransform.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,71 @@ | ||
package ca.bc.gov.iamp.bcparis.transformation; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
import ca.bc.gov.iamp.bcparis.exception.message.MessageTransformException; | ||
import ca.bc.gov.iamp.bcparis.model.message.Layer7Message; | ||
import ca.bc.gov.iamp.bcparis.model.message.body.Body; | ||
import ca.bc.gov.iamp.bcparis.util.RegexTokenizer; | ||
import ca.bc.gov.iamp.bcparis.util.XMLUtil; | ||
|
||
@Service | ||
public class MessageTransform { | ||
|
||
private final Logger log = LoggerFactory.getLogger(MessageTransform.class); | ||
|
||
public Layer7Message parse(Layer7Message message) { | ||
log.info("Message parsing."); | ||
|
||
message = removeCDATA(message); | ||
message = parseCDATA(message); | ||
|
||
return message; | ||
} | ||
|
||
/** | ||
* Remove the CDATA tags | ||
* | ||
* @param message | ||
* Example: <![CDATA[\rSN:M00001-0001 MT:MUF | ||
* MSID:BRKR-190703-20:40:43\nFROM:BC41127\nTO:BC41028]]> | ||
* @return Example: SN:M00001-0001 MT:MUF | ||
* MSID:BRKR-190703-20:40:43\nFROM:BC41127\nTO:BC41028 | ||
*/ | ||
private Layer7Message removeCDATA(Layer7Message message) { | ||
Body body = message.getEnvelope().getBody(); | ||
String msgFFmt = XMLUtil.extractCDATAFromMsgFFmt(body.getMsgFFmt()); | ||
body.setMsgFFmt(msgFFmt); | ||
return message; | ||
} | ||
|
||
private Layer7Message parseCDATA(Layer7Message message) { | ||
try { | ||
String msgFFmt = message.getEnvelope().getBody().getMsgFFmt(); | ||
|
||
List<String> attributes = extractCDATAAttributes(msgFFmt); | ||
|
||
message.getEnvelope().getBody().setCdataAttributes(attributes); | ||
|
||
return message; | ||
} catch (Exception e) { | ||
throw new MessageTransformException("Error during the message transformation.", e); | ||
} | ||
} | ||
|
||
public static List<String> extractCDATAAttributes(final String text) { | ||
List<String> delimiters = Arrays.asList("SN:", "MT:", "MSID:", "FROM:", "TO:", "SUBJ:", "TEXT:", "RE:", | ||
"TestRNS:", // Satellite test | ||
"SNME:", //POR and Driver | ||
"DL:", //Driver | ||
"LIC:", "ODN:", "TAG:", "FLC:", "VIN:", "REG:", "RNS:", "RVL:", // Vehicle | ||
"\\n","\\\\n", "\n\n", "\\\\n\\\\n"); // New line and New line escaped (backslash) | ||
|
||
return new RegexTokenizer(text, delimiters).getTokens(); | ||
} | ||
|
||
} |