Skip to main content

Customer Management in Webui

Understanding Customer in Webui

The Customer class represents a bank customer, including their personal and financial information. This class provides various methods to manage customer data, such as creating, editing, and deleting customer instances.

Customer Attributes

The Customer class includes several attributes to store customer information. These attributes are:

  • customerNumber
  • sortcode
  • name
  • address
  • dob (date of birth)
  • creditScore
  • creditScoreReviewDate
  • editingCustomer

These attributes are defined in the Customer class to store customer information.

	private String customerNumber;

private String sortcode;

private String name;

private String address;

private Date dob;

private String creditScore;

private Date creditScoreReviewDate;

private Boolean editingCustomer;

Creating a Customer

To create a new customer, click on the 'Create customer' button on the landing page. This action will invoke the addToDB method to add the customer to the database.

Viewing Customer Details

To view customer details, click the 'View customer details' button on the landing page. This will display all stored information about the customer.

Adding a Customer to the Database

The addToDB method is used to add a new customer to the database. It creates a CustomerJSON object with the customer's details and sends a request to the CustomerResource to create the customer externally. If the response status is 201, it parses the response and updates the customer's details.


The addToDB method adds a customer to the database by creating a CustomerJSON object and sending a request to the CustomerResource.

	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
{

Updating Customer Information

The updateThis method updates an existing customer's information in the database. It creates a CustomerJSON object with the updated details and sends a request to the CustomerResource to update the customer externally. If the response status is 200, it parses the response and updates the customer's details.

Deleting a Customer from the Database

The deleteFromDB method deletes a customer from the database. It sends a request to the CustomerResource to delete the customer externally. If the response status is 200, it confirms the deletion.


The deleteFromDB method deletes a customer from the database by sending a request to the CustomerResource.

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

Checking if a Customer Exists in the Database

The inDB method checks if a customer exists in the database. It sends a request to the CustomerResource to retrieve the customer details. If the response status is 200, it confirms the existence of the customer.


The inDB method checks if a customer exists in the database by sending a request to the CustomerResource.

	/**
* inDB
*
* Checks if the customer is in the database
*
* @return
*/
public boolean inDB()
{
CustomerResource myCustomerResource = new CustomerResource();

Response myCustomerResponse = null;
String myCustomerString = null;
JSONObject myCustomer = null;

myCustomerResponse = myCustomerResource
.getCustomerExternal(Long.parseLong(this.customerNumber));
if (myCustomerResponse.getStatus() == 200)
{
myCustomerString = myCustomerResponse.getEntity().toString();
try

Displaying Customer Information

The showInfo method displays all stored information about a customer, including their credit score if the customer is being edited.


The showInfo method displays all stored information about a customer.

	/**
* showInfo
*
* Displays all the info stored about the customer Will show a credit score
* if the customer is being edited
*
*/
public void showInfo()
{

if (Boolean.FALSE.equals(editingCustomer))
{
logger.log(Level.INFO, () -> DASHES + this.customerNumber + ":"
+ this.sortcode + DASHES);
logger.log(Level.INFO, () -> "Sortcode - " + this.sortcode);
logger.log(Level.INFO, () -> "Customer name - " + this.getName());
logger.log(Level.INFO,
() -> "Customer address - " + this.getAddress());
logger.log(Level.INFO, () -> "Customer Date of Birth - "
+ this.getDob().toString());
logger.log(Level.INFO, () -> "Customer is new");

 

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