Skip to main content

Creating a New Customer Flow

In this document, we will explain the process of creating a new customer. The process involves the following steps: initiating the customer creation, processing the customer data, writing the data to the database, and establishing a database connection.

The flow starts with initiating the customer creation process by receiving customer data in JSON format. This data is then processed internally and prepared for database insertion. The system ensures that a connection to the database is established, and if not, it creates a new one. Finally, the customer data is written to the database.

Flow drill down


writeCreateCustomerExternal

First, the writeCreateCustomerExternal method is called to initiate the customer creation process. It receives the customer data in JSON format and calls the writeCreateCustomerInternal method to handle the internal processing.

	@POST
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
@Path("/createCustomer")
public Response writeCreateCustomerExternal(
ProcessedTransactionCreateCustomerJSON myCreatedCustomer)
{
Response myResponse = writeCreateCustomerInternal(myCreatedCustomer);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
return myResponse;
}


writeCreateCustomerInternal

Next, the writeCreateCustomerInternal method processes the customer data and attempts to write it to the database. It calls the writeCreateCustomer method to perform the actual database insertion.

	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();
}

}


writeCreateCustomer

Then, the writeCreateCustomer method prepares the customer data for insertion into the database. It formats the data, opens a database connection, and executes the SQL insert statement.

	public boolean writeCreateCustomer(String sortCode2, String accountNumber,
double amountWhichWillBeZero, Date customerDOB, String customerName,
String customerNumber)
{
logger.entering(this.getClass().getName(), WRITE_CREATE_CUSTOMER);
sortOutDateTimeTaskString();
String createCustomerDescription = "";
createCustomerDescription = createCustomerDescription
.concat(padSortCode(Integer.parseInt(sortCode2)));

createCustomerDescription = createCustomerDescription
.concat(padCustomerNumber(customerNumber));
StringBuilder myStringBuilder = new StringBuilder();
for (int z = customerName.length(); z < 14; z++)
{
myStringBuilder.append("0");
}
myStringBuilder.append(customerName);
createCustomerDescription = createCustomerDescription
.concat(myStringBuilder.substring(0, 14));



openConnection

Moving to the openConnection method, it ensures that a connection to the DB2 database is established. If a connection is not already available, it calls the openConnectionInternal method to create a new one.

	protected void openConnection()
{
// Open a connection to the DB2 database
logger.entering(this.getClass().getName(), "openConnection()");

Integer taskNumberInteger = Task.getTask().getTaskNumber();
String db2ConnString = DB2CONN.concat(taskNumberInteger.toString());
logger.log(Level.FINE,
() -> "Attempting to get DB2CONN for task number "
+ taskNumberInteger.toString());
this.conn = (Connection) cornedBeef.get(db2ConnString);
if (this.conn == null)
{
HBankDataAccess.incrementConnCount();
logger.log(Level.FINE,
() -> "Attempting to create DB2CONN for task number "
+ taskNumberInteger.toString());
// Attempt to open a connection
openConnectionInternal();
logger.log(Level.FINE,
() -> "Creation succcessful for DB2CONN for task number "


openConnectionInternal

Finally, the openConnectionInternal method attempts to establish a new database connection using the JNDI lookup. If successful, it stores the connection for reuse and increments the connection count.

	@SuppressWarnings("unchecked")
void openConnectionInternal()
{
logger.entering(this.getClass().getName(), "openConnectionInternal");
String jndiString = "jdbc/defaultCICSDataSource";
Context ctx;

try
{
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(jndiString);
logger.log(Level.FINE, () -> "jndi string is " + jndiString);
// If there is no current connection
if (this.conn == null)
{
logger.log(Level.FINE,
() -> "About to attempt to get DB2 connection");
// Try and get a connection
this.conn = ds.getConnection();
this.conn.setTransactionIsolation(
Connection.TRANSACTION_READ_UNCOMMITTED);

 

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