Skip to main content

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 method filters and counts customers based on the provided filter criteria. It checks if the filter is based on customer name, customer number, or if no filter is provided, it retrieves all customers.

	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 like', the method extracts the customer name from the filter and calls getCustomersByNameExternal to get the count of customers matching the name.

			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 =', the method extracts the customer number from the filter and calls getCustomerExternal to check if a customer with that number exists.

			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 to retrieve all customers and count them.

			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 method retrieves customers based on the provided limit, offset, and countOnly parameters. It calls getCustomersInternal to perform the actual retrieval.

	@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 method retrieves customers by name based on the provided limit, offset, and countOnly parameters. It calls getCustomersByNameInternal to perform the actual retrieval.

	@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 method performs the actual retrieval of customers by name. It checks if only the count is needed or retrieves the full customer details.

	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 method performs the actual retrieval of customers based on the provided limit, offset, and countOnly parameters. It checks if only the count is needed or retrieves the full customer details.

	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 method retrieves customers by name from the VSAM file. It iterates through the file and filters customers based on the provided name, limit, and offset.

	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