[FINERACT-211] Corrected code to avoid detached entity persist exception
This commit is contained in:
+12
-6
@@ -233,17 +233,21 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) {
|
if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||||
final AccountTransferDetails accountTransferDetails = this.accountTransferDetailRepository.findOne(data.accountDetailId());
|
|
||||||
final SavingsAccount fromSavingsAccount = null;
|
final SavingsAccount fromSavingsAccount = null;
|
||||||
final boolean isRegularTransaction = true;
|
final boolean isRegularTransaction = true;
|
||||||
final boolean isExceptionForBalanceCheck = false;
|
final boolean isExceptionForBalanceCheck = false;
|
||||||
accountTransferDetails.accountTransferStandingInstruction().updateLatsRunDate(transactionDate.toDate());
|
|
||||||
AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount, data.fromAccountType(),
|
AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount, data.fromAccountType(),
|
||||||
data.toAccountType(), data.fromAccount().accountId(), data.toAccount().accountId(), data.name()
|
data.toAccountType(), data.fromAccount().accountId(), data.toAccount().accountId(), data.name()
|
||||||
+ " Standing instruction trasfer ", null, null, null, null, data.toTransferType(), null, null, data
|
+ " Standing instruction trasfer ", null, null, null, null, data.toTransferType(), null, null, data
|
||||||
.transferType().getValue(), accountTransferDetails, null, null, null, null, fromSavingsAccount,
|
.transferType().getValue(), null, null, null, null, null, fromSavingsAccount,
|
||||||
isRegularTransaction, isExceptionForBalanceCheck);
|
isRegularTransaction, isExceptionForBalanceCheck);
|
||||||
transferAmount(sb, accountTransferDTO, data.getId());
|
final boolean transferCompleted = transferAmount(sb, accountTransferDTO, data.getId());
|
||||||
|
|
||||||
|
if(transferCompleted){
|
||||||
|
final String updateQuery = "UPDATE m_account_transfer_standing_instructions SET last_run_date = ? where id = ?";
|
||||||
|
this.jdbcTemplate.update(updateQuery, transactionDate.toDate(), data.getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); }
|
if (sb.length() > 0) { throw new JobExecutionException(sb.toString()); }
|
||||||
@@ -254,7 +258,8 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst
|
|||||||
* @param sb
|
* @param sb
|
||||||
* @param accountTransferDTO
|
* @param accountTransferDTO
|
||||||
*/
|
*/
|
||||||
private void transferAmount(final StringBuilder sb, final AccountTransferDTO accountTransferDTO, final Long instructionId) {
|
private boolean transferAmount(final StringBuilder sb, final AccountTransferDTO accountTransferDTO, final Long instructionId) {
|
||||||
|
boolean transferCompleted = true;
|
||||||
StringBuffer errorLog = new StringBuffer();
|
StringBuffer errorLog = new StringBuffer();
|
||||||
StringBuffer updateQuery = new StringBuffer(
|
StringBuffer updateQuery = new StringBuffer(
|
||||||
"INSERT INTO `m_account_transfer_standing_instructions_history` (`standing_instruction_id`, `status`, `amount`,`execution_time`, `error_log`) VALUES (");
|
"INSERT INTO `m_account_transfer_standing_instructions_history` (`standing_instruction_id`, `status`, `amount`,`execution_time`, `error_log`) VALUES (");
|
||||||
@@ -284,6 +289,7 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst
|
|||||||
}
|
}
|
||||||
updateQuery.append(instructionId).append(",");
|
updateQuery.append(instructionId).append(",");
|
||||||
if (errorLog.length() > 0) {
|
if (errorLog.length() > 0) {
|
||||||
|
transferCompleted = false;
|
||||||
updateQuery.append("'failed'").append(",");
|
updateQuery.append("'failed'").append(",");
|
||||||
} else {
|
} else {
|
||||||
updateQuery.append("'success'").append(",");
|
updateQuery.append("'success'").append(",");
|
||||||
@@ -292,6 +298,6 @@ public class StandingInstructionWritePlatformServiceImpl implements StandingInst
|
|||||||
updateQuery.append(", now(),");
|
updateQuery.append(", now(),");
|
||||||
updateQuery.append("'").append(errorLog.toString()).append("')");
|
updateQuery.append("'").append(errorLog.toString()).append("')");
|
||||||
this.jdbcTemplate.update(updateQuery.toString());
|
this.jdbcTemplate.update(updateQuery.toString());
|
||||||
|
return transferCompleted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user