diff --git a/core-connector-interface/src/main/resources/api.yaml b/core-connector-interface/src/main/resources/api.yaml index ea1f9b1..c4f9cf7 100644 --- a/core-connector-interface/src/main/resources/api.yaml +++ b/core-connector-interface/src/main/resources/api.yaml @@ -209,7 +209,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/mojaloopTransferState' + $ref: '#/components/schemas/transferStatusResponse' 400: $ref: '#/components/responses/400' 404: @@ -1638,6 +1638,18 @@ components: - WAITING_FOR_QUOTE_ACCEPTANCE `AUTO_ACCEPT_QUOTE` is set to "false" and quote information has been returned, waiting to be accepted by the Payer DFSP using a `PUT /sendmoney/{transferId}` request. - COMPLETED The transfer has completed successfully. + transferStatusResponse: + type: object + properties: + transferId: + $ref: '#/components/schemas/mojaloopIdentifier' + transferState: + $ref: '#/components/schemas/transferStatus' + completedTimestamp: + $ref: '#/components/schemas/timestamp' + description: Time and date when the transaction was completed. + example: "2020-05-19T08:38:08.699-04:00" + responses: '400': description: Malformed or missing required headers or parameters @@ -1719,4 +1731,4 @@ components: schema: pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ type: string - description: Transfer identifier. \ No newline at end of file + description: Transfer identifier. diff --git a/core-connector/lib/core-connectors-camel-common-1.1.1-SNAPSHOT.jar b/core-connector/lib/core-connectors-camel-common-1.1.1-SNAPSHOT.jar deleted file mode 100644 index fc95223..0000000 Binary files a/core-connector/lib/core-connectors-camel-common-1.1.1-SNAPSHOT.jar and /dev/null differ diff --git a/core-connector/lib/core-connectors-camel-common-1.1.3-SNAPSHOT.jar b/core-connector/lib/core-connectors-camel-common-1.1.3-SNAPSHOT.jar new file mode 100644 index 0000000..c2b051a Binary files /dev/null and b/core-connector/lib/core-connectors-camel-common-1.1.3-SNAPSHOT.jar differ diff --git a/core-connector/pom.xml b/core-connector/pom.xml index 929ea5a..0518cf7 100644 --- a/core-connector/pom.xml +++ b/core-connector/pom.xml @@ -187,9 +187,9 @@ com.modus.adapter.exception cbs-adapters-exception-handling - 1.1.0-SNAPSHOT + 1.1.3-SNAPSHOT system - ${basedir}/lib/core-connectors-camel-common-1.1.1-SNAPSHOT.jar + ${basedir}/lib/core-connectors-camel-common-1.1.3-SNAPSHOT.jar org.json diff --git a/core-connector/src/main/java/com/modusbox/client/jaxrs/TransfersApiImpl.java b/core-connector/src/main/java/com/modusbox/client/jaxrs/TransfersApiImpl.java index 871703a..17e3e64 100644 --- a/core-connector/src/main/java/com/modusbox/client/jaxrs/TransfersApiImpl.java +++ b/core-connector/src/main/java/com/modusbox/client/jaxrs/TransfersApiImpl.java @@ -2,7 +2,7 @@ import com.modusbox.client.api.TransfersApi; import com.modusbox.client.model.FulfilNotification; -import com.modusbox.client.model.MojaloopTransferState; +import com.modusbox.client.model.TransferStatusResponse; import com.modusbox.client.model.TransferRequestInbound; import com.modusbox.client.model.TransferResponseInbound; @@ -12,7 +12,7 @@ public class TransfersApiImpl implements TransfersApi { @Override - public MojaloopTransferState getTransfersByTransferId(@Pattern(regexp = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$") String transferId) { + public TransferStatusResponse getTransfersByTransferId(@Pattern(regexp = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$") String transferId) { return null; } diff --git a/core-connector/src/main/java/com/modusbox/client/processor/CheckMojaloopError.java b/core-connector/src/main/java/com/modusbox/client/processor/CheckMojaloopError.java new file mode 100644 index 0000000..344ecbd --- /dev/null +++ b/core-connector/src/main/java/com/modusbox/client/processor/CheckMojaloopError.java @@ -0,0 +1,56 @@ +package com.modusbox.client.processor; + +import com.google.gson.Gson; +import com.modusbox.client.customexception.CCCustomException; +import com.modusbox.client.enums.ErrorCode; +import com.modusbox.log4j2.message.CustomJsonMessage; +import com.modusbox.log4j2.message.CustomJsonMessageImpl; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.LinkedHashMap; + +public class CheckMojaloopError implements Processor { + + CustomJsonMessage customJsonMessage = new CustomJsonMessageImpl(); + + public void process(Exchange exchange) throws Exception { + Gson gson = new Gson(); + String s = gson.toJson(exchange.getIn().getBody(), LinkedHashMap.class); + JSONObject respObject = new JSONObject(s); + int errorCode = 0; + String errorMessage = ""; + + try { + errorCode = respObject.getInt("statusCode"); + errorMessage = respObject.getString("message"); + if (errorCode == 3208) { + customJsonMessage.logJsonMessage("error", String.valueOf(exchange.getIn().getHeader("X-CorrelationId")), + "Processing the exception at CheckMojaloopError", null, null, respObject.toString()); + throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.TRANSFER_ID_NOT_FOUND)); + } + else if (errorCode == 400) { + customJsonMessage.logJsonMessage("error", String.valueOf(exchange.getIn().getHeader("X-CorrelationId")), + "Processing the exception at CheckMojaloopError", null, null, respObject.toString()); + if (errorMessage.startsWith(".path.transferId should match pattern")) { + throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.MALFORMED_SYNTAX)); + } + else { + throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.GENERIC_VALIDATION_ERROR)); + } + } + else { + customJsonMessage.logJsonMessage("error", String.valueOf(exchange.getIn().getHeader("X-CorrelationId")), + "Processing the exception at CheckMojaloopError, unhandled error code", null, null, respObject.toString()); + throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.INTERNAL_SERVER_ERROR, "Error while retrieving transfer state, please retry later.")); + } + } catch (JSONException e) { + System.out.println("Problem extracting error code from Mojaloop error response occurred."); + throw new CCCustomException(ErrorCode.getErrorResponse(ErrorCode.INTERNAL_SERVER_ERROR)); + } + + } + +} diff --git a/core-connector/src/main/java/com/modusbox/client/router/CustomErrorRouter.java b/core-connector/src/main/java/com/modusbox/client/router/CustomErrorRouter.java index 6beac4d..004f0e2 100644 --- a/core-connector/src/main/java/com/modusbox/client/router/CustomErrorRouter.java +++ b/core-connector/src/main/java/com/modusbox/client/router/CustomErrorRouter.java @@ -2,11 +2,13 @@ import com.modusbox.client.processor.CheckCBSError; import com.modusbox.client.processor.CustomErrorProcessor; +import com.modusbox.client.processor.CheckMojaloopError; import org.apache.camel.builder.RouteBuilder; public final class CustomErrorRouter extends RouteBuilder { private CustomErrorProcessor customErrorProcessor = new CustomErrorProcessor(); private CheckCBSError checkCBSError = new CheckCBSError(); + private CheckMojaloopError checkMojaloopError = new CheckMojaloopError(); public void configure() { @@ -18,5 +20,10 @@ public void configure() { //.process(exchange -> System.out.println()) .process(checkCBSError) ; + + from("direct:catchMojaloopError") +// .process(exchange -> System.out.println()) + .process(checkMojaloopError) + ; } -} \ No newline at end of file +} diff --git a/core-connector/src/main/java/com/modusbox/client/router/TransfersRouter.java b/core-connector/src/main/java/com/modusbox/client/router/TransfersRouter.java index e0f74f6..66150f6 100644 --- a/core-connector/src/main/java/com/modusbox/client/router/TransfersRouter.java +++ b/core-connector/src/main/java/com/modusbox/client/router/TransfersRouter.java @@ -89,10 +89,22 @@ public void configure() { "'Tracking the response', 'Verify the response', null)") // .process(exchange -> System.out.println()) + .choice() + .when(simple("${body['statusCode']} != null")) +// .process(exchange -> System.out.println()) + .to("direct:catchMojaloopError") + .endDoTry() + +// .process(exchange -> System.out.println()) + + .choice() + .when(simple("${body['fulfil']} != null")) +// .process(exchange -> System.out.println()) .marshal().json() .transform(datasonnet("resource:classpath:mappings/getTransfersResponse.ds")) .setBody(simple("${body.content}")) .marshal().json() + .endDoTry() /* * END processing @@ -101,6 +113,8 @@ public void configure() { "'Final Response: ${body}', " + "null, null, 'Response of GET /transfers/${header.transferId} API')") + .doCatch(CCCustomException.class, HttpOperationFailedException.class, JSONException.class) + .to("direct:extractCustomErrors") .doFinally().process(exchange -> { ((Histogram.Timer) exchange.getProperty(TIMER_NAME_GET)).observeDuration(); // stop Prometheus Histogram metric }).end() diff --git a/core-connector/src/main/resources/mappings/getTransfersResponse.ds b/core-connector/src/main/resources/mappings/getTransfersResponse.ds index c49f5b5..7ea3d14 100644 --- a/core-connector/src/main/resources/mappings/getTransfersResponse.ds +++ b/core-connector/src/main/resources/mappings/getTransfersResponse.ds @@ -1,3 +1,5 @@ { - "mojaloopTransferState": payload.fulfil.body.transferState -} \ No newline at end of file + "transferId": payload.transferId, + "transferState": payload.fulfil.body.transferState, + "completedTimestamp": payload.fulfil.body.completedTimestamp +}