Creating a New Bank Account
In this document, we will explain the process of creating a new bank account. The process involves several steps including validating the new account details, retrieving existing customer accounts, checking account limits, and finally creating the new account.
The flow starts with validating the new account details provided by the user. If the details are valid, the system retrieves existing accounts for the customer to ensure the customer exists and to check how many accounts they already have. If the customer has not exceeded the maximum allowed number of accounts, the system proceeds to create the new account. The new account details are then recorded in the database, and a response with the new account information is returned to the user.
Flow drill down
Validating the New Account
First, the createAccountInternal
JSONObject error = validateNewAccount(account);
if (error != null)
{
myResponse = Response.status(400).entity(error.toString()).build();
logger.exiting(this.getClass().getName(), CREATE_ACCOUNT_INTERNAL,
myResponse);
return myResponse;
Retrieving Customer Accounts
Next, the method retrieves existing accounts for the customer using getAccountsByCustomerInternal
Response accountsOfThisCustomer = thisAccountsResource
.getAccountsByCustomerInternal(customerNumberLong);
if (accountsOfThisCustomer.getStatus() != 200)
{
// If accountsOfThisCustomer returns status 404, create new
// JSONObject containing the error message
if (accountsOfThisCustomer.getStatus() == 404)
{
error = new JSONObject();
error.put(JSON_ERROR_MSG, CUSTOMER_NUMBER_LITERAL
+ customerNumberLong.longValue() + CANNOT_BE_FOUND);
logger.log(Level.WARNING, () -> CUSTOMER_NUMBER_LITERAL
+ customerNumberLong.longValue() + CANNOT_BE_FOUND);
myResponse = Response.status(404).entity(error.toString())
.build();
logger.exiting(this.getClass().getName(),
CREATE_ACCOUNT_INTERNAL, myResponse);
return myResponse;
}
error = new JSONObject();
error.put(JSON_ERROR_MSG, CUSTOMER_NUMBER_LITERAL
Checking Account Limits
Then, the method checks if the customer has reached the maximum allowed number of accounts. If the limit is exceeded, an error response is returned, preventing the creation of additional accounts.
long accountCount = (Long) myAccountsJSON.get(JSON_NUMBER_OF_ACCOUNTS);
// Does the customer have ten or more accounts?
if (accountCount >= MAXIMUM_ACCOUNTS_PER_CUSTOMER)
{
error = new JSONObject();
error.put(JSON_ERROR_MSG,
CUSTOMER_NUMBER_LITERAL + customerNumberLong.longValue()
+ " cannot have more than ten accounts.");
logger.log(Level.WARNING,
() -> (CUSTOMER_NUMBER_LITERAL
+ customerNumberLong.longValue()
+ " cannot have more than ten accounts."));
myResponse = Response.status(400).entity(error.toString()).build();
logger.exiting(this.getClass().getName(), CREATE_ACCOUNT_INTERNAL,
myResponse);
return myResponse;
}
Creating the New Account
Finally, the method creates the new account by calling createAccount
com.ibm.cics.cip.bankliberty.web.db2.Account db2Account = new com.ibm.cics.cip.bankliberty.web.db2.Account();
db2Account.setSortcode(this.getSortCode().toString());
db2Account = db2Account.createAccount(account, this.getSortCode());
// Add data to JSONObject
if (db2Account != null)
{
response.put(JSON_SORT_CODE, db2Account.getSortcode().trim());
response.put("id", db2Account.getAccountNumber());
response.put(JSON_CUSTOMER_NUMBER, db2Account.getCustomerNumber());
response.put(JSON_ACCOUNT_TYPE, db2Account.getType().trim());
response.put(JSON_AVAILABLE_BALANCE,
BigDecimal.valueOf(db2Account.getAvailableBalance()));
response.put(JSON_ACTUAL_BALANCE,
BigDecimal.valueOf(db2Account.getActualBalance()));
response.put(JSON_INTEREST_RATE,
BigDecimal.valueOf(db2Account.getInterestRate()));
response.put(JSON_OVERDRAFT, db2Account.getOverdraftLimit());
response.put(JSON_LAST_STATEMENT_DATE,
db2Account.getLastStatement().toString().trim());
response.put(JSON_NEXT_STATEMENT_DATE,
db2Account.getNextStatement().toString().trim());
Where is this flow used?
This flow is used multiple times in the codebase as represented in the following diagram:
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human