Skip to content

Commit be8f999

Browse files
committed
- Update Translator version to 4.1.0
- Update MX version to `22.4.1` - Add `direction` in CBPR+ MX to MT translator
1 parent 003c026 commit be8f999

File tree

8 files changed

+60
-31
lines changed

8 files changed

+60
-31
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
</parent>
1111
<groupId>com.paymentcomponents.libraries</groupId>
1212
<artifactId>rest-sdk-wrapper</artifactId>
13-
<version>1.9.7</version>
13+
<version>1.10.0</version>
1414
<name>rest-sdk-wrapper</name>
1515
<description>Wrapper for Payment Components Financial Messaging Libraries</description>
1616

1717
<properties>
1818
<java.version>1.8</java.version>
1919
<smv.version>22.0.0</smv.version>
20-
<mx.version>22.2.0</mx.version>
20+
<mx.version>22.4.1</mx.version>
2121
<sepa.version>22.0.0</sepa.version>
22-
<translator.version>3.42.0</translator.version>
22+
<translator.version>4.1.0</translator.version>
2323
</properties>
2424

2525
<repositories>

src/main/java/com/paymentcomponents/libraries/rest/sdk/wrapper/controller/CbprTranslatorController.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
1111
import org.springframework.beans.factory.annotation.Autowired;
12-
import org.springframework.web.bind.annotation.PostMapping;
13-
import org.springframework.web.bind.annotation.RequestBody;
14-
import org.springframework.web.bind.annotation.RequestMapping;
15-
import org.springframework.web.bind.annotation.RestController;
12+
import org.springframework.web.bind.annotation.*;
1613

1714
import javax.servlet.http.HttpServletRequest;
1815

@@ -90,9 +87,9 @@ public String translateMtToMx(@RequestBody String mtMessage, HttpServletRequest
9087
}
9188
)
9289
@PostMapping(value = "/mx/to/mt", consumes = "text/plain", produces = "text/plain")
93-
public String translateMxToMt(@RequestBody String mtMessage, HttpServletRequest req) throws Exception {
90+
public String translateMxToMt(@RequestBody String mtMessage, @RequestParam(defaultValue = "O") String direction, HttpServletRequest req) throws Exception {
9491
logger.info("LogID=" + req.getAttribute(REQUEST_LOG_ID) + " mt message=" + mtMessage);
95-
return cbprTranslatorService.translateMxToMt(mtMessage);
92+
return cbprTranslatorService.translateMxToMt(mtMessage, direction);
9693
}
9794

9895
}

src/main/java/com/paymentcomponents/libraries/rest/sdk/wrapper/service/CbprTranslatorService.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import gr.datamation.converter.cbpr.utils.CbprMessageValidationUtils;
88
import gr.datamation.converter.common.exceptions.InvalidMtMessageException;
99
import gr.datamation.converter.common.exceptions.InvalidMxMessageException;
10+
import gr.datamation.converter.common.exceptions.StopTranslationException;
11+
import gr.datamation.converter.common.exceptions.TranslationUnhandledException;
1012
import gr.datamation.converter.common.utils.MtMessageValidationUtils;
1113
import org.springframework.stereotype.Service;
1214

@@ -24,15 +26,18 @@ public String translateMtToMx(String mtMessage) throws InvalidMessageException,
2426
} catch (InvalidMxMessageException ex) {
2527
throw new InvalidMessageException(
2628
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
27-
} catch (Exception ex) {
29+
} catch (StopTranslationException e) {
2830
throw new InvalidMessageException(
29-
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
31+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
32+
} catch (TranslationUnhandledException e) {
33+
throw new InvalidMessageException(
34+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
3035
}
3136
}
3237

33-
public String translateMxToMt(String mxMessage) throws InvalidMessageException, JsonProcessingException {
38+
public String translateMxToMt(String mxMessage, String direction) throws InvalidMessageException, JsonProcessingException {
3439
try {
35-
String translatedMessage = CbprTranslator.translateMxToMt(mxMessage); //throws InvalidMxMessageException
40+
String translatedMessage = CbprTranslator.translateMxToMt(mxMessage, direction); //throws InvalidMxMessageException
3641
MtMessageValidationUtils.parseAndValidateMtMessage(translatedMessage); //throws InvalidMtMessageException
3742
return translatedMessage;
3843
} catch (InvalidMxMessageException ex) {
@@ -41,9 +46,12 @@ public String translateMxToMt(String mxMessage) throws InvalidMessageException,
4146
} catch (InvalidMtMessageException ex) {
4247
throw new InvalidMessageException(
4348
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
44-
} catch (Exception ex) {
49+
} catch (StopTranslationException e) {
50+
throw new InvalidMessageException(
51+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
52+
} catch (TranslationUnhandledException e) {
4553
throw new InvalidMessageException(
46-
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
54+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
4755
}
4856
}
4957

src/main/java/com/paymentcomponents/libraries/rest/sdk/wrapper/service/RtgsTranslatorService.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import com.paymentcomponents.libraries.rest.sdk.wrapper.exception.InvalidMessageException;
66
import gr.datamation.converter.common.exceptions.InvalidMtMessageException;
77
import gr.datamation.converter.common.exceptions.InvalidMxMessageException;
8+
import gr.datamation.converter.common.exceptions.StopTranslationException;
9+
import gr.datamation.converter.common.exceptions.TranslationUnhandledException;
10+
import gr.datamation.converter.common.utils.MtMessageValidationUtils;
811
import gr.datamation.converter.rtgs.RtgsTranslator;
912
import gr.datamation.converter.rtgs.utils.RtgsMessageValidationUtils;
1013
import org.springframework.stereotype.Service;
@@ -14,6 +17,7 @@ public class RtgsTranslatorService {
1417

1518
public String translateMtToMx(String mtMessage) throws InvalidMessageException, JsonProcessingException {
1619
try {
20+
MtMessageValidationUtils.parseAndValidateMtMessage(mtMessage); //Input is not validated from sdk for target2, we validate it in order to prevent NullPointers
1721
String translatedMessage = RtgsTranslator.translateMtToMx(mtMessage); //throws InvalidMtMessageException
1822
RtgsMessageValidationUtils.autoParseAndValidateRtgsMessage(translatedMessage); //throws InvalidMxMessageException
1923
return translatedMessage;
@@ -23,24 +27,27 @@ public String translateMtToMx(String mtMessage) throws InvalidMessageException,
2327
} catch (InvalidMxMessageException ex) {
2428
throw new InvalidMessageException(
2529
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
26-
} catch (Exception ex) {
30+
} catch (StopTranslationException e) {
2731
throw new InvalidMessageException(
28-
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
32+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
33+
} catch (TranslationUnhandledException e) {
34+
throw new InvalidMessageException(
35+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
2936
}
3037
}
3138

3239
public String translateMxToMt(String mxMessage) throws InvalidMessageException, JsonProcessingException {
3340
try {
34-
return RtgsTranslator.translateMxToMt(mxMessage); //output should not validated for now
41+
return RtgsTranslator.translateMxToMt(mxMessage); //output should not validated for Target2
3542
} catch (InvalidMxMessageException ex) {
3643
throw new InvalidMessageException(
3744
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
38-
} catch (InvalidMtMessageException ex) {
45+
} catch (StopTranslationException e) {
3946
throw new InvalidMessageException(
40-
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
41-
} catch (Exception ex) {
47+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
48+
} catch (TranslationUnhandledException e) {
4249
throw new InvalidMessageException(
43-
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
50+
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
4451
}
4552
}
4653

src/test/java/com/paymentcomponents/libraries/rest/sdk/wrapper/controller/CbprTranslatorControllerTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.hamcrest.Matchers.hasSize;
2424
import static org.hamcrest.Matchers.is;
2525
import static org.mockito.ArgumentMatchers.anyString;
26+
import static org.mockito.ArgumentMatchers.eq;
2627
import static org.mockito.BDDMockito.given;
2728
import static org.mockito.BDDMockito.then;
2829
import static org.mockito.Mockito.reset;
@@ -113,7 +114,7 @@ public void givenInvalidMtMessage_whenTranslateMtToMx_thenReturnValidationErrors
113114
@Test
114115
public void givenValidMxMessage_whenTranslateMxToMt_thenReturnMtMessage() throws Exception {
115116
//GIVEN
116-
given(cbprTranslatorService.translateMxToMt(anyString())).willReturn(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_RESPONSE);
117+
given(cbprTranslatorService.translateMxToMt(anyString(), eq("O"))).willReturn(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_RESPONSE);
117118

118119
//WHEN
119120
mvc.perform(post("/translator/cbpr/mx/to/mt")
@@ -126,7 +127,7 @@ public void givenValidMxMessage_whenTranslateMxToMt_thenReturnMtMessage() throws
126127
.andExpect(content().contentType(new MediaType(MediaType.TEXT_PLAIN, StandardCharsets.UTF_8)))
127128
.andExpect(content().string(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_RESPONSE));
128129

129-
then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
130+
then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");
130131
}
131132

132133
@Test
@@ -143,7 +144,7 @@ public void givenInvalidMxMessage_whenTranslateMxToMt_thenReturnValidationErrors
143144
" \"column\": 22\n" +
144145
" }\n" +
145146
"]";
146-
given(cbprTranslatorService.translateMxToMt(anyString())).willThrow(new InvalidMessageException(errorResponse));
147+
given(cbprTranslatorService.translateMxToMt(anyString(), eq("O"))).willThrow(new InvalidMessageException(errorResponse));
147148

148149
//WHEN
149150
mvc.perform(post("/translator/cbpr/mx/to/mt")
@@ -162,7 +163,7 @@ public void givenInvalidMxMessage_whenTranslateMxToMt_thenReturnValidationErrors
162163
.andExpect(jsonPath("$[0].line", is(4)))
163164
.andExpect(jsonPath("$[0].column", is(22)));
164165

165-
then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
166+
then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");
166167
}
167168

168169
}

src/test/java/com/paymentcomponents/libraries/rest/sdk/wrapper/integration/RtgsTranslatorIntegrationTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ public void givenValidMtMessage_whenTranslateMtToMx_thenReturnMxMessage() throws
5252
@Test
5353
public void givenInvalidMtMessage_whenTranslateMtToMx_thenReturnValidationErrors() throws Exception {
5454
//GIVEN
55-
String errorResponse = "\"Message could not be translated\"";
55+
String errorResponse = "[ {\n" +
56+
" \"tagName\" : \"20\",\n" +
57+
" \"description\" : \"SV16 - Mandatory Tag is missing \",\n" +
58+
" \"sequence\" : null,\n" +
59+
" \"occurs\" : \"1\",\n" +
60+
" \"line\" : null,\n" +
61+
" \"messageIndex\" : null,\n" +
62+
" \"errorCode\" : \"SV16\"\n" +
63+
"} ]";
5664

5765
//WHEN
5866
mvc.perform(post("/translator/rtgs/mt/to/mx")
@@ -62,7 +70,7 @@ public void givenInvalidMtMessage_whenTranslateMtToMx_thenReturnValidationErrors
6270
//THEN
6371
.andExpect(status().isBadRequest())
6472
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
65-
.andExpect(content().string(errorResponse));
73+
.andExpect(content().string(replaceLineEndings(errorResponse)));
6674
}
6775

6876
@Test

src/test/java/com/paymentcomponents/libraries/rest/sdk/wrapper/service/CbprTranslatorServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void givenValidMxMessage_whenTranslateMxToMt_thenReturnMtMessage() throws
7373
.replaceAll("2106021108", ".*");
7474

7575
//WHEN
76-
String result = cbprTranslatorService.translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
76+
String result = cbprTranslatorService.translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");
7777

7878
//THEN
7979
assertTrue(replaceLineEndings(result).matches(replaceLineEndings(expectedAsRegex)));
@@ -94,7 +94,7 @@ public void givenInvalidMxMessage_whenTranslateMxToMt_thenThrowInvalidMessageExc
9494

9595
//WHEN
9696
InvalidMessageException exception = assertThrows(InvalidMessageException.class, () -> {
97-
cbprTranslatorService.translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
97+
cbprTranslatorService.translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");
9898
});
9999

100100
//THEN

src/test/java/com/paymentcomponents/libraries/rest/sdk/wrapper/service/RtgsTranslatorServiceTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ public void givenValidMtMessage_whenTranslateMtToMx_thenReturnMxMessage() throws
4444
@Test
4545
public void givenInvalidMtMessage_whenTranslateMtToMx_thenThrowInvalidMessageException() {
4646
//GIVEN
47-
String exceptionBody = "\"Message could not be translated\"";
47+
String exceptionBody = "[ {\n" +
48+
" \"tagName\" : \"20\",\n" +
49+
" \"description\" : \"SV16 - Mandatory Tag is missing \",\n" +
50+
" \"sequence\" : null,\n" +
51+
" \"occurs\" : \"1\",\n" +
52+
" \"line\" : null,\n" +
53+
" \"messageIndex\" : null,\n" +
54+
" \"errorCode\" : \"SV16\"\n" +
55+
"} ]";
4856

4957
//WHEN
5058
InvalidMessageException exception = assertThrows(InvalidMessageException.class, () -> {

0 commit comments

Comments
 (0)