Filtering and Counting Customers
In this document, we will explain the process of filtering and counting customers based on different criteria. The process involves checking if the filter is based on customer name, customer number, or if no filter is provided, retrieving all customers.
The flow is simple and involves three steps: filtering by customer name, filtering by customer number, and retrieving all customers if no filter is provided.
Flow drill down
Filtering and Counting Customers
The howMany
private void howMany(String filter)
{
CustomerResource myCustomerResource = new CustomerResource();
Response myCustomerResponse = null;
// 0123456789012345678901234
try
{
if (filter.startsWith(" AND CUSTOMER_NAME like '"))
{
String customerNameFilter = filter.substring(25);
customerNameFilter = customerNameFilter.substring(0,
customerNameFilter.length() - 1);
myCustomerResponse = myCustomerResource
.getCustomersByNameExternal(customerNameFilter, 0, 0,
true);
String myCustomersString = myCustomerResponse.getEntity()
Filtering by Customer Name
If the filter starts with 'AND CUSTOMER_NAME
getCustomersByNameExternal
if (filter.startsWith(" AND CUSTOMER_NAME like '"))
{
String customerNameFilter = filter.substring(25);
customerNameFilter = customerNameFilter.substring(0,
customerNameFilter.length() - 1);
myCustomerResponse = myCustomerResource
.getCustomersByNameExternal(customerNameFilter, 0, 0,
true);
String myCustomersString = myCustomerResponse.getEntity()
.toString();
JSONObject myCustomersJSON;
myCustomersJSON = JSONObject.parse(myCustomersString);
long customerCount = (Long) myCustomersJSON
.get(JSON_NUMBER_OF_CUSTOMERS);
this.count = (int) customerCount;
}
Filtering by Customer Number
If the filter starts with 'AND CUSTOMER_NUMBER
getCustomerExternal
if (filter.startsWith(" AND CUSTOMER_NUMBER = "))
{
String customerNumberFilter = filter.substring(23);
Long customerNumber = Long.parseLong(customerNumberFilter);
myCustomerResponse = myCustomerResource
.getCustomerExternal(customerNumber);
String myCustomersString = myCustomerResponse.getEntity()
.toString();
JSONObject myCustomerJSON;
this.count = 0;
if (myCustomerResponse.getStatus() == 200)
{
myCustomerJSON = JSONObject.parse(myCustomersString);
String id = (String) myCustomerJSON.get(JSON_ID);
if (id != null)
{
this.count = 1;
}
}
}
Retrieving All Customers
If no filter is provided, the method calls getCustomersExternal
if (filter.length() == 0)
{
myCustomerResponse = myCustomerResource
.getCustomersExternal(250000, 0, true);
String myCustomersString = myCustomerResponse.getEntity()
.toString();
if (myCustomerResponse.getStatus() == 200)
{
JSONObject myCustomersJSON;
myCustomersJSON = JSONObject.parse(myCustomersString);
long customerCount = (Long) myCustomersJSON
.get(JSON_NUMBER_OF_CUSTOMERS);
this.count = (int) customerCount;
}
else
{
logger.log(Level.SEVERE, () -> "Error getting customers");
}
}
External Customer Retrieval
The getCustomersExternal
countOnly
getCustomersInternal
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getCustomersExternal(@QueryParam("limit") Integer limit,
@QueryParam("offset") Integer offset,
@QueryParam("countOnly") Boolean countOnly)
{
logger.entering(this.getClass().getName(),
"getCustomersExternal(Integer limit, Integer offset, Boolean countOnly) "
+ limit + " " + offset + " " + countOnly);
boolean countOnlyReal = false;
if (countOnly != null)
{
countOnlyReal = countOnly.booleanValue();
}
Response myResponse = getCustomersInternal(limit, offset,
countOnlyReal);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"getCustomersExternal(Integer limit, Integer offset, Boolean countOnly)",
myResponse);
External Customer Retrieval by Name
The getCustomersByNameExternal
countOnly
getCustomersByNameInternal
@GET
@Path("/name")
@Produces(MediaType.APPLICATION_JSON)
public Response getCustomersByNameExternal(@QueryParam("name") String name,
@QueryParam("limit") Integer limit,
@QueryParam("offset") Integer offset,
@QueryParam("countOnly") Boolean countOnly)
{
logger.entering(this.getClass().getName(),
"getCustomersByNameExternal(String name, Integer limit, Integer offset, Boolean countOnly) "
+ name + " " + limit + " " + offset + " " + countOnly);
boolean countOnlyReal = false;
if (countOnly != null)
{
countOnlyReal = countOnly.booleanValue();
}
if (offset == null)
{
offset = 0;
}
Internal Customer Retrieval by Name
The getCustomersByNameInternal
public Response getCustomersByNameInternal(@QueryParam("name") String name,
@QueryParam("limit") int limit, @QueryParam("offset") int offset,
boolean countOnly)
{
logger.entering(this.getClass().getName(),
"getCustomersByNameInternal(String name, Integer limit, Integer offset, Boolean countOnly) "
+ name + " " + limit + " " + offset + " " + countOnly);
Integer sortCode = this.getSortCode();
JSONObject response = new JSONObject();
JSONArray customers = null;
if (countOnly)
{
com.ibm.cics.cip.bankliberty.web.vsam.Customer vsamCustomer = new com.ibm.cics.cip.bankliberty.web.vsam.Customer();
long numberOfCustomers = 0;
numberOfCustomers = vsamCustomer
.getCustomersByNameCountOnly(sortCode.intValue(), name);
response.put(JSON_NUMBER_OF_CUSTOMERS, numberOfCustomers);
}
else
Internal Customer Retrieval
The getCustomersInternal
countOnly
public Response getCustomersInternal(@QueryParam("limit") Integer limit,
@QueryParam("offset") Integer offset, boolean countOnly)
{
logger.entering(this.getClass().getName(),
"getCustomersInternal(Integer limit, Integer offset, Boolean countOnly) "
+ limit + " " + offset + " " + countOnly);
Integer sortCode = this.getSortCode();
JSONObject response = new JSONObject();
JSONArray customers = null;
if (offset == null)
{
offset = 0;
}
if (limit == null)
{
limit = 250000;
}
Customer Retrieval by Name
The getCustomersByName
public Customer[] getCustomersByName(int sortCode, int limit, int offset,
String name)
{
logger.entering(this.getClass().getName(),
GET_CUSTOMERS_BY_NAME_WITH_OFFSET_AND_LIMIT);
Customer[] temp = new Customer[1000000];
int stored = 0;
customerFile.setName(FILENAME);
myCustomer = new CUSTOMER();
holder = new RecordHolder();
keyHolder = new KeyHolder();
byte[] key = buildKey(sortCode, 0);
// We need to convert the key to EBCDIC
String keyString = new String(key);
try
{
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