Java code

Sul63n
WebPatternsAssignment131.doc

JAVA REST SERVER ASSIGNMENT

Functional Requirements

You are required to build a full REST server that reads or writes to a database for an Order Management System. The system will be able to create, amend and retrieve the follow types – Customer, Product, Order. Details of the fields in the database and the json structures for these types are shown below.

The REST interface must have end points (url paths):

/Customer

/Product

/Order

Each end points should have the following request types:

GET: Returns an array of json objects

POST: Sends a new json object, returns a uniqueId

PUT: Sends an updated object.

The server should be built using a Glassfish server and MySql database.

The system should interact with the database using JDBC and implement DAO classes.

JSON DATA SPECIFICATION

Examples of JSON Objects required for each end point are as follows:

Customer for GET, POST, PUT:

{

CustomerId: 1,

CustomerReference : “123”,

CustomerName: “cust1”,

CreditLimit : 100.3,

Phone: “808 112345”,

Active: true

}

Product for GET, POST, PUT:

{

ProductId : 1,

ProductCode : “1234A”,

ProductName : “widget1”,

ProductDescription : “info about widget1”,

QtyInStock : 100,

Active : true

}

Order for GET:

{

OrderId : 10,

OrderDate : “09/10/2019”,

OrderStatus : “New”,

Customer : {

CustomerId: 1,

CustomerReference : “123”,

CustomerName: “cust1”,

Phone : “808 112345”

}, {

Products: [ {

orderQty : 5,

ProductId : 1,

Price : 123.3,

ProductCode : “1234A”,

ProductName : “widget1”,

ProductDescription : “info about widget1”

},{

orderQty : 10,

ProductId : 2,

ProductCode : “12345A”,

ProductName : “widget1”,

ProductDescription : “info about widget1”

}

] }

}

Order for POST, PUT:

{

OrderId : 101254,

OrderDate : “09/10/2019”,

OrderStatus : “New”,

Customer : {

CustomerId: 1

}, {

Products: [ {

orderQty : 5,

ProductId : 1,

Price : 123.3

},{

orderQty : 10,

ProductId : 2,

Price: 234.3

}

] }

}

DATABASE SPECFICATION

The database should have the following structure:

Database: OrderManagementSystem

Table: Customer

CustomerId: INT, UNIQUE, PRIMARY KEY

CustomerReference: VARCHAR(10)

CustomerName: VARCHAR(40)

CreditLimit: DECIMAL (5, 2)

phone: VARCHAR(20)

Active: TINYINT(1)

Table: Product

ProductId: INT, UNIQUE, PRIMARY KEY

ProductCode: VARCHAR(20)

ProductName: VARCHAR(40)

ProductDescription: VARCHAR(100)

Price: DECIMAL (5, 2)

QtyInStock: INT

Active: TINYINT(1)

Table: Order

OrderId: INT, UNIQUE, PRIMARY KEY

CustomerUniqueId: INT

OrderDate: DATE

OrderStatus: INT

Table: OrderDetail

OrderId: INT

ProductId: INT

OrderQty: INT

ProductPrice: DECIMAL (10,2)

Notes:

OrderStatus can have the values 1=New, 2=InProgress, 3=Completed, 4=Cancelled

An OrderDetail will have an entry for each product included in the order.

If the Active field in Product or Customer is set to false the data is archived and should not be retrieved in subsequent GETs. This is equivalent to a delete.

You may wish to use an AUTO_INCREMENT for unique Id fields.

DUE DATE: 04/11/2019