final String description = request.getParameter("description");
/* Must perform an internal transfert */
if (scope.equals("internal")) {
final Long accountToId = Long.parseLong(request.getParameter("accountTo"));
final Account accountFrom = accountService.findAccountById(accountFromId);
final Account accountTo = accountService.findAccountById(accountToId);
if (accountFrom != null && accountTo != null) {
if (amount > accountFrom.getTotalAmount()) {
request.setAttribute("error", true);
request.setAttribute("errorString", "You can't perform this transfert with your account amount");
}
else if (accountFromId.equals(accountToId)) {
request.setAttribute("error", true);
request.setAttribute("errorString", "You can't transfert to the same account");
}
else
{
transfertService.performInternalTransfert(accountFrom, accountTo, amount, description);
request.setAttribute("informationString", "Your transfert has succeeded");
}
doGet(request, response);
}
}
else if (scope.equals("external")) {
final Account accountFrom = accountService.findAccountById(accountFromId);
final String bbanEstablishmentCode = request.getParameter("bbanEstablishmentCode");
final String bbanBranchCode = request.getParameter("bbanBranchCode");
final String bbanAccountNumber = request.getParameter("bbanAccountNumber");
final String bbanKey = request.getParameter("bbanKey");
final BasicBankAccountNumber bban = new BasicBankAccountNumber(bbanEstablishmentCode,
bbanBranchCode, bbanAccountNumber, bbanKey);
if (amount > accountFrom.getTotalAmount()) {
request.setAttribute("error", true);
request.setAttribute("errorString", "You can't perform this transfert with your account amount");
}
/*
if (!bban.isKeyValid()) {
request.setAttribute("error", true);
request.setAttribute("errorString", "The BBAN Key is invalid");
doGet(request, response);
}
*/
else if (bbanEstablishmentCode.equals(ESTABLISHMENT_CODE)) {
final Long accountToId = Long.parseLong(
BasicBankAccountNumber.normalizedAccountNumber(bbanAccountNumber));
final Account accountTo = accountService.findAccountById(accountToId);
if (accountTo != null) {
transfertService.performAnotherCustomerTransfert(accountFrom, accountTo, bban.toString(),
amount, description);
request.setAttribute("informationString", "Your transfert has succeeded");