From 34324ab1d6cc175f52128424c9df53023ff761c8 Mon Sep 17 00:00:00 2001 From: rishy Date: Wed, 6 Aug 2014 15:09:43 +0530 Subject: [PATCH] extended API-docs and exceptions in Batch API --- api-docs/apiLive.htm | 34 ++++++++++++++++--- .../integrationtests/BatchApiTest.java | 3 -- .../batch/exception/ErrorHandler.java | 21 ++++++++++-- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index c243416f4..3aac0da3c 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -2897,7 +2897,7 @@ Content-Type: application/json Request Body: -   +  

Batch requests in a single transaction

@@ -3001,7 +3001,7 @@ Successful transaction response:
-   +  

Batch API Errors

@@ -3010,9 +3010,35 @@ Successful transaction response: In Batch API without "enclosingTransaction=true", if one of the response is erroneous, then an appropriate status code will be set for that request and the error message will be returned in it's "body", while all other requests will return successful response with a status code of "200".

-
- +
+ +   +
+
+

Available Command Strategies

+ +

+ These are the currently available command strategies within the Mifos Batch API. So, these listed operations can be executed using a Batch Request. +

+ +
+ +
+  
diff --git a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/BatchApiTest.java b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/BatchApiTest.java index 1246fd8f1..7bc4629e4 100644 --- a/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/BatchApiTest.java +++ b/mifosng-provider/src/integrationTest/java/org/mifosplatform/integrationtests/BatchApiTest.java @@ -406,9 +406,6 @@ public class BatchApiTest { final List response = BatchHelper.postBatchRequestsWithoutEnclosingTransaction(this.requestSpec, this.responseSpec, jsonifiedRequest); - System.out.println(response.get(3)); - System.out.println(response.get(4)); - Assert.assertEquals("Verify Status Code 200 for Approve Loan", 200L, (long) response.get(3).getStatusCode()); Assert.assertEquals("Verify Status Code 200 for Disburse Loan", 200L, (long) response.get(4).getStatusCode()); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/batch/exception/ErrorHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/batch/exception/ErrorHandler.java index e664337c2..30febcf36 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/batch/exception/ErrorHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/batch/exception/ErrorHandler.java @@ -12,9 +12,12 @@ import org.mifosplatform.infrastructure.core.exception.PlatformInternalServerExc import org.mifosplatform.infrastructure.core.exception.UnsupportedParameterException; import org.mifosplatform.infrastructure.core.exceptionmapper.PlatformApiDataValidationExceptionMapper; import org.mifosplatform.infrastructure.core.exceptionmapper.PlatformDataIntegrityExceptionMapper; +import org.mifosplatform.infrastructure.core.exceptionmapper.PlatformDomainRuleExceptionMapper; import org.mifosplatform.infrastructure.core.exceptionmapper.PlatformInternalServerExceptionMapper; import org.mifosplatform.infrastructure.core.exceptionmapper.PlatformResourceNotFoundExceptionMapper; import org.mifosplatform.infrastructure.core.exceptionmapper.UnsupportedParameterExceptionMapper; +import org.mifosplatform.portfolio.loanaccount.exception.MultiDisbursementDataRequiredException; +import org.mifosplatform.portfolio.loanproduct.exception.LinkedAccountRequiredException; import org.springframework.transaction.TransactionException; import com.google.gson.Gson; @@ -81,8 +84,22 @@ public class ErrorHandler extends RuntimeException { return new ErrorInfo(403, 3001, errorBody); + } else if (exception instanceof LinkedAccountRequiredException) { + + final PlatformDomainRuleExceptionMapper mapper = new PlatformDomainRuleExceptionMapper(); + final String errorBody = jsonHelper.toJson(mapper.toResponse((LinkedAccountRequiredException) exception).getEntity()); + + return new ErrorInfo(403, 3002, errorBody); + + } else if (exception instanceof MultiDisbursementDataRequiredException) { + + final PlatformDomainRuleExceptionMapper mapper = new PlatformDomainRuleExceptionMapper(); + final String errorBody = jsonHelper.toJson(mapper.toResponse((MultiDisbursementDataRequiredException) exception).getEntity()); + + return new ErrorInfo(403, 3003, errorBody); + } else if (exception instanceof TransactionException) { - return new ErrorInfo(400, 4001, "Exception " + exception.getCause() + " " + exception.getMessage()); + return new ErrorInfo(400, 4001, "{\"Exception\": " + exception.getMessage()+"}"); } else if (exception instanceof PlatformInternalServerException) { @@ -92,6 +109,6 @@ public class ErrorHandler extends RuntimeException { return new ErrorInfo(500, 5001, errorBody); } - return new ErrorInfo(500, 9999, exception.toString() + " " + exception.getStackTrace()); + return new ErrorInfo(500, 9999, "{\"Exception\": " + exception.toString() + "}"); } }