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
The flow starts by initializing the AccountsResource
AccountsResource
Flow drill down
Handling account retrieval based on different filters
The doGet
AccountsResource
AccountsResource
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
AccountsResource
doGet
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
getAccountsByCustomerInternal
@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
getAccountsInternal
@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
getAccountsByBalanceWithOffsetAndLimitInternal
@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
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
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
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