Skip to content

Commit

Permalink
- Update Translator version to 4.1.0
Browse files Browse the repository at this point in the history
- Update MX version to `22.4.1`
- Add `direction` in CBPR+ MX to MT translator
  • Loading branch information
johnmara-pc14 committed Nov 23, 2022
1 parent 003c026 commit be8f999
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 31 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
</parent>
<groupId>com.paymentcomponents.libraries</groupId>
<artifactId>rest-sdk-wrapper</artifactId>
<version>1.9.7</version>
<version>1.10.0</version>
<name>rest-sdk-wrapper</name>
<description>Wrapper for Payment Components Financial Messaging Libraries</description>

<properties>
<java.version>1.8</java.version>
<smv.version>22.0.0</smv.version>
<mx.version>22.2.0</mx.version>
<mx.version>22.4.1</mx.version>
<sepa.version>22.0.0</sepa.version>
<translator.version>3.42.0</translator.version>
<translator.version>4.1.0</translator.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -90,9 +87,9 @@ public String translateMtToMx(@RequestBody String mtMessage, HttpServletRequest
}
)
@PostMapping(value = "/mx/to/mt", consumes = "text/plain", produces = "text/plain")
public String translateMxToMt(@RequestBody String mtMessage, HttpServletRequest req) throws Exception {
public String translateMxToMt(@RequestBody String mtMessage, @RequestParam(defaultValue = "O") String direction, HttpServletRequest req) throws Exception {
logger.info("LogID=" + req.getAttribute(REQUEST_LOG_ID) + " mt message=" + mtMessage);
return cbprTranslatorService.translateMxToMt(mtMessage);
return cbprTranslatorService.translateMxToMt(mtMessage, direction);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import gr.datamation.converter.cbpr.utils.CbprMessageValidationUtils;
import gr.datamation.converter.common.exceptions.InvalidMtMessageException;
import gr.datamation.converter.common.exceptions.InvalidMxMessageException;
import gr.datamation.converter.common.exceptions.StopTranslationException;
import gr.datamation.converter.common.exceptions.TranslationUnhandledException;
import gr.datamation.converter.common.utils.MtMessageValidationUtils;
import org.springframework.stereotype.Service;

Expand All @@ -24,15 +26,18 @@ public String translateMtToMx(String mtMessage) throws InvalidMessageException,
} catch (InvalidMxMessageException ex) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
} catch (Exception ex) {
} catch (StopTranslationException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
} catch (TranslationUnhandledException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
}
}

public String translateMxToMt(String mxMessage) throws InvalidMessageException, JsonProcessingException {
public String translateMxToMt(String mxMessage, String direction) throws InvalidMessageException, JsonProcessingException {
try {
String translatedMessage = CbprTranslator.translateMxToMt(mxMessage); //throws InvalidMxMessageException
String translatedMessage = CbprTranslator.translateMxToMt(mxMessage, direction); //throws InvalidMxMessageException
MtMessageValidationUtils.parseAndValidateMtMessage(translatedMessage); //throws InvalidMtMessageException
return translatedMessage;
} catch (InvalidMxMessageException ex) {
Expand All @@ -41,9 +46,12 @@ public String translateMxToMt(String mxMessage) throws InvalidMessageException,
} catch (InvalidMtMessageException ex) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
} catch (Exception ex) {
} catch (StopTranslationException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
} catch (TranslationUnhandledException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.paymentcomponents.libraries.rest.sdk.wrapper.exception.InvalidMessageException;
import gr.datamation.converter.common.exceptions.InvalidMtMessageException;
import gr.datamation.converter.common.exceptions.InvalidMxMessageException;
import gr.datamation.converter.common.exceptions.StopTranslationException;
import gr.datamation.converter.common.exceptions.TranslationUnhandledException;
import gr.datamation.converter.common.utils.MtMessageValidationUtils;
import gr.datamation.converter.rtgs.RtgsTranslator;
import gr.datamation.converter.rtgs.utils.RtgsMessageValidationUtils;
import org.springframework.stereotype.Service;
Expand All @@ -14,6 +17,7 @@ public class RtgsTranslatorService {

public String translateMtToMx(String mtMessage) throws InvalidMessageException, JsonProcessingException {
try {
MtMessageValidationUtils.parseAndValidateMtMessage(mtMessage); //Input is not validated from sdk for target2, we validate it in order to prevent NullPointers
String translatedMessage = RtgsTranslator.translateMtToMx(mtMessage); //throws InvalidMtMessageException
RtgsMessageValidationUtils.autoParseAndValidateRtgsMessage(translatedMessage); //throws InvalidMxMessageException
return translatedMessage;
Expand All @@ -23,24 +27,27 @@ public String translateMtToMx(String mtMessage) throws InvalidMessageException,
} catch (InvalidMxMessageException ex) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
} catch (Exception ex) {
} catch (StopTranslationException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
} catch (TranslationUnhandledException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
}
}

public String translateMxToMt(String mxMessage) throws InvalidMessageException, JsonProcessingException {
try {
return RtgsTranslator.translateMxToMt(mxMessage); //output should not validated for now
return RtgsTranslator.translateMxToMt(mxMessage); //output should not validated for Target2
} catch (InvalidMxMessageException ex) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
} catch (InvalidMtMessageException ex) {
} catch (StopTranslationException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(ex.getValidationErrorList()));
} catch (Exception ex) {
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getTranslationErrorList()));
} catch (TranslationUnhandledException e) {
throw new InvalidMessageException(
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString("Message could not be translated"));
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(e.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.reset;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void givenInvalidMtMessage_whenTranslateMtToMx_thenReturnValidationErrors
@Test
public void givenValidMxMessage_whenTranslateMxToMt_thenReturnMtMessage() throws Exception {
//GIVEN
given(cbprTranslatorService.translateMxToMt(anyString())).willReturn(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_RESPONSE);
given(cbprTranslatorService.translateMxToMt(anyString(), eq("O"))).willReturn(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_RESPONSE);

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

then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");
}

@Test
Expand All @@ -143,7 +144,7 @@ public void givenInvalidMxMessage_whenTranslateMxToMt_thenReturnValidationErrors
" \"column\": 22\n" +
" }\n" +
"]";
given(cbprTranslatorService.translateMxToMt(anyString())).willThrow(new InvalidMessageException(errorResponse));
given(cbprTranslatorService.translateMxToMt(anyString(), eq("O"))).willThrow(new InvalidMessageException(errorResponse));

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

then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
then(cbprTranslatorService).should(times(1)).translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ public void givenValidMtMessage_whenTranslateMtToMx_thenReturnMxMessage() throws
@Test
public void givenInvalidMtMessage_whenTranslateMtToMx_thenReturnValidationErrors() throws Exception {
//GIVEN
String errorResponse = "\"Message could not be translated\"";
String errorResponse = "[ {\n" +
" \"tagName\" : \"20\",\n" +
" \"description\" : \"SV16 - Mandatory Tag is missing \",\n" +
" \"sequence\" : null,\n" +
" \"occurs\" : \"1\",\n" +
" \"line\" : null,\n" +
" \"messageIndex\" : null,\n" +
" \"errorCode\" : \"SV16\"\n" +
"} ]";

//WHEN
mvc.perform(post("/translator/rtgs/mt/to/mx")
Expand All @@ -62,7 +70,7 @@ public void givenInvalidMtMessage_whenTranslateMtToMx_thenReturnValidationErrors
//THEN
.andExpect(status().isBadRequest())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(content().string(errorResponse));
.andExpect(content().string(replaceLineEndings(errorResponse)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void givenValidMxMessage_whenTranslateMxToMt_thenReturnMtMessage() throws
.replaceAll("2106021108", ".*");

//WHEN
String result = cbprTranslatorService.translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
String result = cbprTranslatorService.translateMxToMt(TestConstants.VALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");

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

//WHEN
InvalidMessageException exception = assertThrows(InvalidMessageException.class, () -> {
cbprTranslatorService.translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST);
cbprTranslatorService.translateMxToMt(TestConstants.INVALID_CBPR_TRANSLATOR_MX_TO_MT_REQUEST, "O");
});

//THEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ public void givenValidMtMessage_whenTranslateMtToMx_thenReturnMxMessage() throws
@Test
public void givenInvalidMtMessage_whenTranslateMtToMx_thenThrowInvalidMessageException() {
//GIVEN
String exceptionBody = "\"Message could not be translated\"";
String exceptionBody = "[ {\n" +
" \"tagName\" : \"20\",\n" +
" \"description\" : \"SV16 - Mandatory Tag is missing \",\n" +
" \"sequence\" : null,\n" +
" \"occurs\" : \"1\",\n" +
" \"line\" : null,\n" +
" \"messageIndex\" : null,\n" +
" \"errorCode\" : \"SV16\"\n" +
"} ]";

//WHEN
InvalidMessageException exception = assertThrows(InvalidMessageException.class, () -> {
Expand Down

0 comments on commit be8f999

Please sign in to comment.