Skip to main content

Retrieving Account Information Flow

In this document, we will explain the process of retrieving account information based on various filters such as balance, account number, and customer number. The process involves initializing the AccountsResource, processing the filter to determine the appropriate retrieval method, and fetching the account data.

The flow starts by initializing the AccountsResource. Then, it processes the filter to determine which method to call for retrieving account information. Depending on the filter, it clears the current list of accounts and calls the appropriate method from AccountsResource to fetch the account data. The methods handle different types of filters, such as balance, account number, and customer number, and support pagination for efficient data retrieval.

Flow drill down


Handling account retrieval based on different filters

The doGet method is responsible for retrieving account information based on different filters such as balance, account number, and customer number. It initializes the AccountsResource and processes the filter to determine which retrieval method to call. Depending on the filter, it clears the current list of accounts and calls the appropriate method from AccountsResource to fetch the account data.

	public void doGet(int limit, int offset, String filter) throws IOException
{

AccountsResource myAccountsResource = new AccountsResource();

Response myAccountsResponse = null;
String myAccountsString = null;
JSONObject myAccountsJSON = null;

try
{

if (filter.contains(" AND ACCOUNT_AVAILABLE_BALANCE"))
{
this.listOfAccounts.clear();
String operator = filter.substring(31, 32);
BigDecimal balance = BigDecimal
.valueOf(Double.parseDouble(filter.substring(34)));

myAccountsResponse = myAccountsResource
.getAccountsByBalanceWithOffsetAndLimitExternal(balance,


Counting accounts based on filters

The howMany method counts the number of accounts that match the given filter. It uses the AccountsResource to fetch the account data and updates the count based on the response. This method is called within doGet when the offset is zero to provide the total count of accounts matching the filter.

	public int howMany(String filter)
{

// AND ACCOUNT_NUMBER = 0000000024
// AND ACCOUNT_CUSTOMER_NUMBER

AccountsResource myAccountsResource = new AccountsResource();
Response myAccountsResponse = null;
this.count = 0;

try
{
if (filter.contains("AND ACCOUNT_AVAILABLE_BALANCE"))
{
// 01234567890123456789012345678901234567890
// AND ACCOUNT_AVAILABLE_BALANCE <= 33558.0

String operator = filter.substring(31, 32);
BigDecimal balance = BigDecimal
.valueOf(Double.parseDouble(filter.substring(34)));



Retrieving accounts by customer number

The getAccountsByCustomerExternal method retrieves accounts owned by a specified customer. It calls the internal method getAccountsByCustomerInternal to fetch the account data and returns the response.

	@GET
@Path("/retrieveByCustomerNumber/{customerNumber}")
@Produces("application/json")
public Response getAccountsByCustomerExternal(
@PathParam(JSON_CUSTOMER_NUMBER) Long customerNumber,
@QueryParam("countOnly") Boolean countOnly)
{
/** This will list accounts owned by a specified customer */
logger.entering(this.getClass().getName(),
"getAccountsByCustomerExternal(Long customerNumber, Boolean countOnly)");

Response myResponse = getAccountsByCustomerInternal(customerNumber);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"getAccountsByCustomerExternal(Long customerNumber, Boolean countOnly)",
myResponse);
return myResponse;
}


Retrieving accounts with pagination

The getAccountsExternal method retrieves a fixed number of accounts starting at a specified offset. It calls the internal method getAccountsInternal to fetch the account data and returns the response.

	@GET
@Produces("application/json")
public Response getAccountsExternal(@QueryParam("limit") Integer limit,
@QueryParam("offset") Integer offset,
@QueryParam("countOnly") Boolean countOnly)
{
// This method returns a fixed number of accounts, up to limit "limit",
// starting at offset "offset"
logger.entering(this.getClass().getName(),
"getAccountsExternal(Integer limit, Integer offset,Boolean countOnly)");
boolean countOnlyReal = false;
if (countOnly != null)
{
countOnlyReal = countOnly.booleanValue();
}
Response myResponse = getAccountsInternal(limit, offset, countOnlyReal);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"getAccountsExternal(Integer limit, Integer offset,Boolean countOnly)",
myResponse);


Retrieving accounts by balance with pagination

The getAccountsByBalanceWithOffsetAndLimitExternal method retrieves accounts with a certain balance, supporting pagination. It calls the internal method getAccountsByBalanceWithOffsetAndLimitInternal to fetch the account data and returns the response.

	@GET
@Path("/balance")
@Produces("application/json")
public Response getAccountsByBalanceWithOffsetAndLimitExternal(
@QueryParam("balance") BigDecimal balance,
@QueryParam("operator") String operator,
@QueryParam("offset") Integer offset,
@QueryParam("limit") Integer limit,
@QueryParam("countOnly") Boolean countOnly)
{
// return only accounts with a certain balance
logger.entering(this.getClass().getName(),
"getAccountsByBalanceWithOffsetAndLimitExternal(BigDecimal balance, String operator, Integer offset, Integer limit, Boolean countOnly");
boolean countOnlyReal = false;
if (countOnly != null)
{
countOnlyReal = countOnly.booleanValue();
}

Response myResponse = getAccountsByBalanceWithOffsetAndLimitInternal(
balance, operator, offset, limit, countOnlyReal);


Internal method for retrieving accounts by balance

The getAccountsByBalanceWithOffsetAndLimitInternal method is the internal implementation for retrieving accounts with a certain balance. It handles the logic for filtering accounts based on the balance and pagination parameters, and constructs the response.

	public Response getAccountsByBalanceWithOffsetAndLimitInternal(
@QueryParam("balance") BigDecimal balance,
@QueryParam("operator") String operator,
@QueryParam("offset") Integer offset,
@QueryParam("limit") Integer limit, boolean countOnly)
{
// return only accounts with a certain balance
logger.entering(this.getClass().getName(),
GET_ACCOUNTS_BY_BALANCE_WITH_OFFSET_AND_LIMIT_INTERNAL);
Response myResponse = null;
boolean lessThan;
if (!operator.startsWith("<") && !(operator.startsWith(">")))
{
JSONObject error = new JSONObject();
error.put(JSON_ERROR_MSG, "Invalid operator, '" + operator
+ "' only <= or >= allowed");
logger.log(Level.WARNING, () -> "Invalid operator, '" + operator
+ "' only <= or >= allowed");
logger.exiting(this.getClass().getName(),
GET_ACCOUNTS_BY_BALANCE_WITH_OFFSET_AND_LIMIT_INTERNAL,
myResponse);


Internal method for retrieving accounts

The getAccountsInternal method is the internal implementation for retrieving accounts with pagination. It handles the logic for fetching accounts from the database and constructing the response.

	public Response getAccountsInternal(Integer limit, Integer offset,
boolean countOnly)
{
logger.entering(this.getClass().getName(),
"getAccountsInternal(Integer limit, Integer offset,boolean countOnly)");
Response myResponse = null;

com.ibm.cics.cip.bankliberty.web.db2.Account db2Account = null;
JSONObject response = new JSONObject();
JSONArray accounts = null;
int numberOfAccounts = 0;
Integer sortCode = this.getSortCode();
// We want to set a limit to try to avoid OutOfMemory Exceptions.
// 250,000 seems a bit large
if (limit == null)
{
limit = 250000;
}
if (limit == 0)
{
limit = 250000;


Internal method for retrieving accounts by customer number

The getAccountsByCustomerInternal method is the internal implementation for retrieving accounts owned by a specified customer. It handles the logic for fetching accounts from the database and constructing the response.

	public Response getAccountsByCustomerInternal(
@PathParam(JSON_CUSTOMER_NUMBER) Long customerNumber)
{
logger.entering(this.getClass().getName(),
GET_ACCOUNTS_BY_CUSTOMER_INTERNAL);

JSONArray accounts = null;
Response myResponse = null;

JSONObject response = new JSONObject();
Integer sortCode = this.getSortCode();
int numberOfAccounts = 0;

CustomerResource myCustomer = new CustomerResource();
Response customerResponse = myCustomer
.getCustomerInternal(customerNumber);

if (customerResponse.getStatus() != 200)
{
if (customerResponse.getStatus() == 404)
{

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human