Adding a Customer to the Database
In this document, we will explain the process of adding a customer to the database. The process involves creating a customer resource, setting customer details, and writing the customer data to the database.
The flow starts by creating a customer resource and setting the customer's details such as address, name, date of birth, and sort code. These details are then passed to the method that initiates the customer creation process. The process includes several validations, writing the customer data to the VSAM database, and finally writing the customer details to the DB2
Flow drill down
addToDB Function
addToDBDiving into the addToDBCustomerResourceCustomerJSONCustomerJSONcreateCustomerExternal
public String addToDB()
{
CustomerResource myCustomerResource = new CustomerResource();
CustomerJSON myCustomerJSON = new CustomerJSON();
myCustomerJSON.setCustomerAddress(this.getAddress());
myCustomerJSON.setCustomerName(this.getName());
myCustomerJSON.setDateOfBirth(this.getDob());
myCustomerJSON.setSortCode(this.getSortcode());
Response myCustomerResponse = myCustomerResource
.createCustomerExternal(myCustomerJSON);
String myCustomerString = null;
JSONObject myCustomer = null;
if (myCustomerResponse.getStatus() == 201)
{
myCustomerString = myCustomerResponse.getEntity().toString();
try
{
createCustomerExternal Function
createCustomerExternalMoving to the createCustomerExternalcreateCustomerInternalHBankDataAccess
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response createCustomerExternal(CustomerJSON customer)
{
logger.entering(this.getClass().getName(),
CREATE_CUSTOMER_EXTERNAL + customer.toString());
Response myResponse = createCustomerInternal(customer);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(), CREATE_CUSTOMER_EXTERNAL_EXIT,
myResponse);
return myResponse;
}
createCustomerInternal Function
createCustomerInternalNext, the createCustomerInternalCustomer
public Response createCustomerInternal(CustomerJSON customer)
{
logger.entering(this.getClass().getName(),
CREATE_CUSTOMER_INTERNAL + customer.toString());
JSONObject response = new JSONObject();
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.createCustomerInternal(), "
+ customer.toString());
logger.exiting(this.getClass().getName(),
CREATE_CUSTOMER_INTERNAL_EXIT, myResponse);
return myResponse;
}
writeCreateCustomerInternal Function
writeCreateCustomerInternalThen, the writeCreateCustomerInternalDB2
public Response writeCreateCustomerInternal(
ProcessedTransactionCreateCustomerJSON myCreatedCustomer)
{
com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction myProcessedTransactionDB2 = new com.ibm.cics.cip.bankliberty.web.db2.ProcessedTransaction();
if (myProcessedTransactionDB2.writeCreateCustomer(
myCreatedCustomer.getSortCode(),
myCreatedCustomer.getAccountNumber(), 0.00,
myCreatedCustomer.getCustomerDOB(),
myCreatedCustomer.getCustomerName(),
myCreatedCustomer.getCustomerNumber()))
{
return Response.ok().build();
}
else
{
return Response.serverError().build();
}
}
createCustomer Function
createCustomerGoing into the createCustomerCustomer
public Customer createCustomer(CustomerJSON customer,
Integer sortCodeInteger)
{
logger.entering(this.getClass().getName(), CREATE_CUSTOMER);
Customer temp = null;
customerFile.setName(FILENAME);
myCustomer = new CUSTOMER();
String sortCodeString = sortCodeInteger.toString();
long customerNumberAsPrimitive = getNextCustomerNumber(sortCodeString);
Long customerNumberLong = Long.valueOf(customerNumberAsPrimitive);
if (customerNumberLong == -1)
{
return null;
}
byte[] key = buildKey(sortCodeInteger, customerNumberLong);
populateCreditScoreAndReviewDate Function
populateCreditScoreAndReviewDateFinally, the populateCreditScoreAndReviewDate
public static CustomerJSON populateCreditScoreAndReviewDate(
CustomerJSON customer)
{
sortOutLogging();
int creditAgencyCount = 5;
/* Set up a random CS review date within the next 21 days */
Calendar calendar = Calendar.getInstance();
long nowMs = calendar.getTimeInMillis();
int next21Days = new Random(calendar.getTimeInMillis()).nextInt(20);
next21Days++;
nowMs = nowMs + (1000L * 60L * 60L * 24L * next21Days);
customer.setReviewDate(new Date(nowMs));
Channel myCreditScoreChannel = null;
AsyncService asService = new AsyncServiceImpl();
List<Future<ChildResponse>> children = new ArrayList<>();
String[] containerID = new String[creditAgencyCount];
int creditScoreTotal = 0;
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human