cath database errors related to savings withdrawals

This commit is contained in:
Vishwas Babu A J
2014-12-02 17:33:19 -08:00
parent f58fc1c116
commit 07052f983e
2 changed files with 29 additions and 19 deletions
@@ -26,6 +26,7 @@ import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.infrastructure.codes.service.CodeValueReadPlatformService;
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException;
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
@@ -37,6 +38,8 @@ import org.mifosplatform.portfolio.savings.data.SavingsAccountTransactionData;
import org.mifosplatform.portfolio.savings.service.SavingsAccountReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.stereotype.Component;
@Path("/savingsaccounts/{savingsId}/transactions")
@@ -119,24 +122,31 @@ public class SavingsAccountTransactionsApiResource {
@Produces({ MediaType.APPLICATION_JSON })
public String transaction(@PathParam("savingsId") final Long savingsId, @QueryParam("command") final String commandParam,
final String apiRequestBodyAsJson) {
try {
final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
CommandProcessingResult result = null;
if (is(commandParam, "deposit")) {
final CommandWrapper commandRequest = builder.savingsAccountDeposit(savingsId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else if (is(commandParam, "withdrawal")) {
final CommandWrapper commandRequest = builder.savingsAccountWithdrawal(savingsId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
CommandProcessingResult result = null;
if (is(commandParam, "deposit")) {
final CommandWrapper commandRequest = builder.savingsAccountDeposit(savingsId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else if (is(commandParam, "withdrawal")) {
final CommandWrapper commandRequest = builder.savingsAccountWithdrawal(savingsId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
if (result == null) {
//
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "deposit", "withdrawal" });
}
return this.toApiJsonSerializer.serialize(result);
} catch (ObjectOptimisticLockingFailureException lockingFailureException) {
throw new PlatformDataIntegrityException("error.msg.savings.concurrent.operations",
"Concurrent Transactions being made on this savings account: " + lockingFailureException.getMessage());
} catch (CannotAcquireLockException cannotAcquireLockException) {
throw new PlatformDataIntegrityException("error.msg.savings.concurrent.operations.unable.to.acquire.lock",
"Unable to acquir lock for this transaction: " + cannotAcquireLockException.getMessage());
}
if (result == null) {
//
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "deposit", "withdrawal" });
}
return this.toApiJsonSerializer.serialize(result);
}
@POST
@@ -1149,16 +1149,16 @@ public class SavingsAccount extends AbstractPersistable<Long> {
accountingBridgeData.put("accrualBasedAccountingEnabled", isAccrualBasedAccountingEnabledOnSavingsProduct());
accountingBridgeData.put("isAccountTransfer", isAccountTransfer);
final List<Map<String, Object>> newLoanTransactions = new ArrayList<>();
final List<Map<String, Object>> newSavingsTransactions = new ArrayList<>();
for (final SavingsAccountTransaction transaction : this.transactions) {
if (transaction.isReversed() && !existingReversedTransactionIds.contains(transaction.getId())) {
newLoanTransactions.add(transaction.toMapData(currencyData));
newSavingsTransactions.add(transaction.toMapData(currencyData));
} else if (!existingTransactionIds.contains(transaction.getId())) {
newLoanTransactions.add(transaction.toMapData(currencyData));
newSavingsTransactions.add(transaction.toMapData(currencyData));
}
}
accountingBridgeData.put("newSavingsTransactions", newLoanTransactions);
accountingBridgeData.put("newSavingsTransactions", newSavingsTransactions);
return accountingBridgeData;
}