Skip to main content

Updating Customer Information Flow

In this document, we will explain the process of updating customer information. The process involves initializing customer data, updating the information externally, handling internal update logic, and finally updating the customer information in the VSAM database.

The flow starts with initializing customer data and setting the necessary fields like address, name, and sort code. Then, the information is updated externally through a method that consumes and produces JSON data. This method calls another method to handle the internal update logic, which includes validating the customer data and updating it in the VSAM database. If the customer is found, the details are updated and returned; otherwise, a not-found flag is set.

Flow drill down


Parsing the customer response and updating customer details

First, the updateThis method initializes a CustomerResource and a CustomerJSON object. It sets the customer's address, name, and sort code in the CustomerJSON object. Then, it calls the updateCustomerExternal method to update the customer information externally. If the response status is 200, it parses the response to update the customer's date of birth, address, name, sort code, and customer number.

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

CustomerJSON myCustomerJSON = new CustomerJSON();

myCustomerJSON.setCustomerAddress(this.getAddress());
myCustomerJSON.setCustomerName(this.getName());
myCustomerJSON.setSortCode(this.getSortcode());
myCustomerJSON.setSortCode(this.getSortcode());

Response myCustomerResponse = myCustomerResource.updateCustomerExternal(
Long.parseLong(this.getCustomerNumber()), myCustomerJSON);

String myCustomerString = null;
JSONObject myCustomer = null;

if (myCustomerResponse.getStatus() == 200)
{
myCustomerString = myCustomerResponse.getEntity().toString();
try


Updating customer information externally

Next, the updateCustomerExternal method is called. This method consumes and produces JSON data. It calls the updateCustomerInternal method to handle the internal update logic and then terminates the HBankDataAccess session before returning the response.

	@PUT
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateCustomerExternal(@PathParam(JSON_ID) Long id,
CustomerJSON customer)
{
logger.entering(this.getClass().getName(),
UPDATE_CUSTOMER_EXTERNAL + id);
Response myResponse = updateCustomerInternal(id, customer);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(), UPDATE_CUSTOMER_EXTERNAL + id,
myResponse);
return myResponse;



Handling internal customer update logic

Then, the updateCustomerInternal method performs several checks on the customer data, such as validating the customer name, title, sort code, and address. If any of these checks fail, it returns an appropriate error response. If all checks pass, it updates the customer information in the VSAM database and constructs a JSON response with the updated customer details.

	public Response updateCustomerInternal(@PathParam(JSON_ID) Long id,
CustomerJSON customer)
{
logger.entering(this.getClass().getName(),
UPDATE_CUSTOMER_INTERNAL + id);

if(customer.getCustomerName() == null)
{
JSONObject error = new JSONObject();
error.put(JSON_ERROR_MSG,
"Customer name is null");
Response myResponse = Response.status(400).entity(error.toString())
.build();
logger.log(Level.WARNING,
() -> "Customer name is null in CustomerResource.updateCustomerInternal(), "
+ customer.toString());
logger.exiting(this.getClass().getName(),
UPDATE_CUSTOMER_INTERNAL_EXIT, myResponse);
return myResponse;
}



Updating customer information in the VSAM database

Finally, the updateCustomer method in the VSAM database is called. This method reads the customer record for update, modifies the customer details, and rewrites the record. If the customer is not found, it returns a Customer object with a notFound flag set to true. Otherwise, it returns the updated Customer object with the new details.

	public Customer updateCustomer(CustomerJSON customer)
{
logger.entering(this.getClass().getName(), UPDATE_CUSTOMER, null);

customerFile.setName(FILENAME);
Customer temp;
holder = new RecordHolder();

Long customerNumberLong = Long.parseLong(customer.getId());

customer.setId(padCustomerNumber(customer.getId()));

byte[] key = buildKey(Integer.valueOf(customer.getSortCode()),
Long.valueOf(customer.getId()));

try
{
customerFile.readForUpdate(key, holder);
myCustomer = new CUSTOMER(holder.getValue());
myCustomer.setCustomerAddress(customer.getCustomerAddress());
myCustomer.setCustomerName(customer.getCustomerName());

 

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