Skip to main content

Customer Deletion Process

In this document, we will explain the process of deleting a customer and their associated accounts from the database. The process involves multiple steps, including initiating the deletion, handling external and internal requests, and ensuring all associated accounts are properly deleted.

The flow starts with initiating the customer deletion process. This involves calling an external function to handle the deletion request. The external function then calls an internal function to perform the actual deletion. The internal function first deletes all associated accounts by calling another function for each account. Once all accounts are deleted, the customer record is deleted, and the transaction is logged.

Flow drill down


deleteFromDB Function

Diving into the deleteFromDB function, it initiates the customer deletion process by calling deleteCustomerExternal and handles the response to update the customer details if the deletion is successful.

	public boolean deleteFromDB()
{
CustomerResource myCustomerResource = new CustomerResource();

Response myCustomerResponse = myCustomerResource.deleteCustomerExternal(
Long.parseLong(this.getCustomerNumber()));

String myCustomerString = null;
JSONObject myCustomer = null;

if (myCustomerResponse.getStatus() == 200)
{
myCustomerString = myCustomerResponse.getEntity().toString();
try
{
myCustomer = JSONObject.parse(myCustomerString);
}
catch (IOException e)
{
logger.log(Level.SEVERE, e::toString);



deleteCustomerExternal Function

The deleteCustomerExternal function is responsible for handling the external request to delete a customer. It calls deleteCustomerInternal to perform the actual deletion and then terminates the data access session.

	@DELETE
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteCustomerExternal(@PathParam(JSON_ID) Long id)
{
logger.entering(this.getClass().getName(),
"deleteCustomerExtnernal(Long id) for customerNumber " + id);
Response myResponse = deleteCustomerInternal(id);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"deleteCustomerExternal(Long id)", myResponse);
return myResponse;
}


deleteCustomerInternal Function

The deleteCustomerInternal function performs the core logic of deleting a customer. It first deletes all associated accounts by calling deleteAccountInternal for each account. If successful, it proceeds to delete the customer record and logs the transaction.

	public Response deleteCustomerInternal(Long id)
{
logger.entering(this.getClass().getName(),
"deleteCustomerInternal(Long id) for customerNumber " + id);

Integer sortCode = this.getSortCode();

JSONObject response = new JSONObject();

if (id.longValue() < 0)
{
// Customer number cannot be negative
response.put(JSON_ERROR_MSG, "Customer number cannot be negative");
Response myResponse = Response.status(404)
.entity(response.toString()).build();
logger.log(Level.WARNING,
() -> "Customer number supplied was negative in deleteCustomerInternal()");
logger.exiting(this.getClass().getName(),
DELETE_CUSTOMER_INTERNAL_EXIT, myResponse);
return myResponse;
}


deleteAccountInternal Function

The deleteAccountInternal function handles the deletion of individual accounts associated with the customer. It ensures that each account is properly deleted and logs the transaction.

	public Response deleteAccountInternal(Long accountNumber)
{
logger.entering(this.getClass().getName(), DELETE_ACCOUNT);
Response myResponse = null;

JSONObject response = new JSONObject();

Integer sortCode = this.getSortCode();

com.ibm.cics.cip.bankliberty.web.db2.Account db2Account = new Account();

db2Account = db2Account.deleteAccount(accountNumber.intValue(),
sortCode.intValue());
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()));

 

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