Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Only need help with the Dao class. Java: Simple Rest Server Instructions Create a simple server that uses simple design patterns Factory: Your server should

Only need help with the Dao class.

Java: Simple Rest Server

Instructions

Create a simple server that uses simple design patterns

  • Factory: Your server should parse the routes and create a new Processor class

    depending on the route

  • Builder: The process method of your Processor should use the Builder pattern to create

    a response.

  • DAO: Make a class that abstracts the data interactions away from the rest of the app

  • Singleton: Wrap your daoinstance as a singleton class

  • Lazy Loading: DAOs should only load data when requested

  • DTO: Your JSON parsing, as well as response objects must be DTOs

    First parse url, then use factory to instantiate correct Processor class. The factory will internally use the builder pattern to give the processor relevant data. Use builder to set the time, and input parameters.

    Processor Class

  • Has a process() method that returns a ResponseDto object

  • Each endpoint is a subclass of Processor

  • Takes a hashmap of key value args

  • Use a factory to create these, based on the endpoint

  • Every processor uses a builder and returns the output ofbuilder.build()

    Response Class

  • This class gets stringified with GSON

  • Needs a ResponseBuilder helper

  • Needs Params Map (String, String)

  • Needs response dto

  • Needs Response Code (String)

    Dao class

  • Singleton

  • Lazy load data

  • 1 DAO per type of endpoint to hold the data

Endpoints Payment Methods

/addPaymentMethod?m ethod=name

  • creates a new payment method and stores it in the paymentMethod DAO

  • assigns a machine code

  • needs Payment DTO + Payment DAO

  • fields:name,machineCode

    /get

  • AllPaymentMethods

Returns list of all payment methods

Items /addItem?name=name&price=price

  • Creates a new item and gives it a price

  • Assigns machine readable code and returns it

  • needs ItemDAO + Item DTO

  • fields: name, price, machineCode

    /listItems

returns all items

Transactions /createTransaction?itemCode=code&paymentMethod=paymentCode

  • Must have valid payment method

  • fields: itemCode, paymentMethod /listTransactions

  • returns all transaction

  • needs TransactionDAO + Transaction DTO

High level steps

  1. Parse request and extract the endpoint

  2. Parse the get args into a hashmap

  3. Use factory to instantiate correct processor class

  4. Call .process(args) and pass in the arguments on this class (args is a hash map of the

    getparams)

  5. Inside the processor it can get or put data through the DAO

  6. Business Logic goes in processor Load/Store logic goes in DAO

  7. Returns a single ResponseDto

  8. Stringify this response dto and pass it into the output stream

Return Format

You will need a response class that looks like this before passing to JSON. "{

"date": "2019-02-10T20:40:59.257Z", // time that this was generated "params": {

"a": 2 // full list of all key value get params

}, responseCode: OK/ERROR "response": {}, // put your responses here

}"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions