Saturday, September 10, 2016

JAVA 20 - Customer Account

Just a disclaimer, the code I've produced here forms a working model of a customer account class to work with.  This is not intended to be a demonstrator of good design for a customer account management system, just a working model we can play around with.

In this last worked out example, we're going to create code for a customer account management system.

Our requirements

[REQ_1]  Users can register their account by providing us their username, an initial password, and their date of birth.

[REQ_2]  Throughout their lifetime with us, customers or people with admin privileges can add or change the following details to a customer account,
  • Full name
  • Mailing address
  • Email
  • Phone number

[REQ_3]  Only the account owner is able to change their password.

[REQ_4]  The username and date of birth are fixed at account creation, and cannot be amended.  In the rare case where someone has forgotten their own birthday, we'll get the value changed in the database.

[REQ_5]  Both the account owner and admins are able to view account details.

[REQ_6]  The account will be fully audited, including every time change of data, every time it's viewed, every time access is denied.  

[REQ_7]  Details of passwords will not be displayed, either within account details or in account view.

[REQ_8]  The account view will also list all audit events.

The solution

I'm not going to go into the same level of detail I have with previous projects.  The code can be found here on Github.

Probably the key thing to look at here is the AuditEvent class.

We have a whole List of these audit objects within our customer CustomerAccountClass.

We add a new AuditEvent for everything we do.

I have a pretty obvious method to check permissions when needed - it's assumed that the method receives the username of the person trying to perform the change.

I mentioned this in the comment in the constructor, but I added a List of admin staff usernames, who have permission to make changes.  The way I did that was a bit of a hack, but hey, I don't want to build a whole system for my demo here.

So when you run, this is a taste of what you get - quite neat!

Extension material

Create admin class

The adminStaff List included within the customer account class is ugly.  Create a class which contains a list of admin staff, and returns whether someone is authorised to make changes or not.

This will separate out between customer data & methods and admin data & methods, and so be considerably tidier.

Don't forget to declare this admin staff within your @Test methods.

Date of birth

I currently handle date of birth as a String, which was just for quick convenience.  Replace it with a date format, you will have to Google to find what types you can find in Java.

1 comment:

  1. Casinos that offer online casino games.
    Sbobet Casino online casino games are open for a long time. Online casinos nowadays change the acceptance of gamblers around the world. Because of the gamblers around the world, they love to play online gambling games because it gives both pleasure. Rich experience exotic So it is not uncommon now that online gambling is gaining popularity.

    For online gambling games, there are online gambling games that offer players a huge selection of online gambling games or live casino games. Electronic games, whether it is playing games, online casino games, any kind of player can choose to play with the satisfaction of the web gclub. Our online casinos are welcome and ready to serve players consistently.

    If the player is thinking to play online games, we want the gambler to choose the service with the website. Online Casinos Our web casino. Our gambling club is never disappointed. The gambler can join in and enjoy playing online gambling games like today at the web คาสิโน