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
CustomerResource
CustomerJSON
CustomerJSON
updateCustomerExternal
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
updateCustomerInternal
HBankDataAccess
@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
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
Customer
notFound
Customer
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