Integrating dao & service layers into mvc design pattern when developing an e-commerce system with java

pdf 9 trang Gia Huy 17/05/2022 5380
Bạn đang xem tài liệu "Integrating dao & service layers into mvc design pattern when developing an e-commerce system with java", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên

Tài liệu đính kèm:

  • pdfintegrating_dao_service_layers_into_mvc_design_pattern_when.pdf

Nội dung text: Integrating dao & service layers into mvc design pattern when developing an e-commerce system with java

  1. INTEGRATING DAO & SERVICE LAYERS INTO MVC DESIGN PATTERN WHEN DEVELOPING AN E-COMMERCE SYSTEM WITH JAVA SVTH: Nguyễn Hữu Bằng, Hoàng Tiến Dũng, Trân Minh Dương, Trần Anh Tú, Nguyễn Thị Thanh Trà GVHD: ThS Nguyễn Thị Hương Tóm tắt - Với sự phát triển của công nghệ, ngày càng có nhiều trang web được phát triển và triển khai trên Internet bằng nhiều công nghệ khác nhau. Một trong số đó là Java Servlet, đi kèm với JSP. Mặc dù các công nghệ khác như JavaScript, ASP. NET, Python ngày càng trở nên phổ biến trong giới phát triển Web, Java vẫn khẳng định là một công nghệ mạnh mẽ và nhất quán. Trong bài báo này, việc tích hợp DAO & Service vào mẫu thiết kế MVC sẽ được thảo luận trong bối cảnh của Dự án Web Java Thương mại Điện tử. Abstract - With the development of technology, more websites are now developed and deployed onto the Internet using various technologies. One of them is Java Servlet, accompanied by JSP. Although other technologies such as JavaScript, ASP. NET, Python have become increasingly popular among Web developers, Java still claims to be a powerful and consistent technology. In this paper, the integration of DAO & Service into the MVC design pattern will be discussed in the context of an Ecommerce Java Web Project. I. Introduction The past 2 years have experienced several outbreaks of the Covid-19 pandemic, which gets almost all daily activities of humans conducted at home. This also leads to the incredible increase in the use of the Internet and online shopping has become a huge interest of online users. Along with the delivery of the Software Engineering 2 course, we, a group of 5 Software Engineering majors, decided to develop an Ecommerce Website as a product for the course progress assessment. Technology-wise, the Website is developed with Java Servlet, JSP (Java Server Page), HTML, CSS, and Javascript, and the Waterfall Software Development Life Cycle is put into practice. In terms of functions, the Website provides both administrators’ managing area and customers’ shopping area, which meets all the basic requirements for an e-commerce website at the present age. This report, thus, will explain the development of the website: how it was developed, what is satisfactorily accomplished, what needs improvement, and what are potential adjustments to achieve better versions in the future. 231
  2. II. Main content 1. MVC with DAO, Service layers in E-commerce System - Lapeki project overview The M - Model Layer corresponds to all the data-related logic that the website has to store. In this project, the Model layer comprises 6 data objects User, Product, Cart, CartLine, Category, Voucher. The V - View Layer is used for all the UI logic of the application, including all Customer and Admin side interfaces. The C - Controller acts as an interface between Model and View components to process all the business logic and incoming requests, manipulate data using the Model component, and interact with the Views to render the final output. Specifically, all Servlet classes will be the controllers handling the incoming request from the browser. The DAO layer is made up of all interfaces that define the standard operations to be performed on a model object(s), and their implementation classes. The Service Layer is an abstraction over domain logic. It defines an application's boundary with a layer of services that establishes a set of available operations and coordinates the application's response in each operation. In particular, the Service layer provides several functions that execute the interfaces in the DAO layers and other functions like Login, Register. Figure 1. MVC design pattern with DAO & Service layers 3. Development of the Lapeki E-Commerce System The Software Development Life Cycle that is chosen for the project is Waterfall SDLC, which includes the following phases: Requirements Analysis, Analysis, Design, Implementation, Testing, Evaluation. 3.1 Requirement Analysis The objective of this phase is to transform the needs and high-level requirements specified in earlier phases into unambiguous (measurable and testable), traceable, complete, 232
  3. consistent, and stakeholder-approved requirements. During the Requirements Analysis Phase, the agency will conduct any procurement needed for the project. This phase also includes the use-case diagram which will describe the functionalities of the whole system. The purpose of this project is to design and develop an e-commerce website where users can browse, shop, and sell. Integrated with logistical and payment support, the asset-light platform claims to make online shopping easy and secure for both sellers and buyers. Therefore, this includes three main actors, which are Customer, Administrator and PayPal Service: ● Administrator: Sign in to the system with a special role, manage orders, products, vouchers, and all accounts of the system. ● Customer: browse the website, view product lists, add products to the shopping cart, and make orders. ● PayPal Service: Provide online payment 3.2 Analysis The system's data models are established during the Analysis process. An Entity- Relationship diagram is a good representation of the data models. Figure 2 - ER diagram The figure above is a combination of entity diagrams with physical data models to describe the diagram structure of the project. Furthermore, an Entity-Relationship (ER) Diagram is a form of flowchart that depicts how “entities” within a structure, such as people, objects, or concepts, interact with one another. According to the requirements specification, 233
  4. there are six objects organized into tables such as User, Cart, CartLine, Voucher, Product, and Category, each with its own set of properties. Moreover, each of the tables in this system can be enhanced during use by adding, removing, and updating data to ensure that all required information is stored and the logic of the system is fulfilled. The relationship between each table is described through the use of the primary key, foreign key, and dash line. User table: used to store the information of the user using the website such as username, password, etc. using column “user_id” as the primary key and provide foreign keys to the cart table. Product table: store all the product information, use foreign keys received from the category table, has a primary key name as “product_id”. Cart table: used to hold the details of all the carts, using “cart_id” as the primary key, receive and use foreign keys from the user table and voucher table. CartLine table: represents every line of product in a cart, uses foreign keys from cart table and product table. Category table: used to store the information of every category, has the “categories” as the primary key provided for the product table as a foreign key. Voucher table: indicates the voucher that applies to cart, provide cart table with a foreign key of “voucher_id”. This diagram will aid developers in comprehending how the database should be implemented in the next section. 3.3 Design 3.3.1 Backend Design & Class Diagram The backend was designed based on the Model-View-Controller (MVC) pattern with some other packages and the view separated and stored outside of the src package. The UML Class diagram was used in our project during the Design phase to give coders a better idea of how they can execute the framework. The Class Diagram depicts the implementation of objects as well as their relationships. The UML Class Diagram will be divided into a comprehensive set, according to the MVC design pattern, to enforce exactly what standards were provided by the requirement as planned. 3.3.2 Frontend Design & User Interface The frontend of this project uses JSP (JavaServer Pages) consisting of HTML markup embedded with JSP tags, together with CSS for style and a small part of JavaScript client-side 234
  5. script to handle UI logic. The views are divided into two main layouts(Admin site and Customer site), each of them is further broken down into smaller components. Each view component comes as a jsp page containing JSP expressions, HTML, and sometimes even JavaScript or JSTL (Java Standard Tag Library) to handle the logic. 3.4 Implementation The implementation of the project is divided into different periods corresponding to different packages of the project code. Overall, the implementation phase starts with creating models, DAO and Service layers, followed by the creation of Controllers and Views. 4. Lapeki E-Commerce System: Outcomes Figure 3. Login and register interface Figure 4. Admin dashboard interface 235
  6. Figure 5. Common list interface Figure 6,7. Editing interface Figure 7,8. Homepage interface 236
  7. Figure 9. Product search result interface Figure 10. Product detail interface Figure 11. Cart detail interface 237
  8. Figure 12. Checkout interface 5. Evaluation 5.1. Advantages Back-end: The backend of the project is designed based on the MVC model, which is the most popular application development model of Java. In addition, the MVC model has a simple structure, so inexperienced coders are easy to adopt. With the independent operating characteristics of each component, we can work simultaneously on each different part of this model, which not only facilitates the project development rapidly but also saves a lot of time. The front-end is implemented by Bootstrap, which is the most well-known front-end open-source toolkit This web application is designed with reusable JSP UI components. It is helpful and friendly to use because it combines HTML with some basic Java coding, and Servlet is in charge of processing logic of the server-side. We have implemented all the core functions of the ordinary E-Commerce Website: Create new account, create new customer, search product, sort product, add to cart, apply the voucher, check out. In particular, the payment function contains two methods for customers to choose from: COD (Cash On Delivery) and PayPal. After customers complete their orders, the application will send an automatic email confirmation to the email lists so that customers can easily check again their checkout and follow their orders. 5.2. Disadvantages One of the most difficult challenges encountered during the development of this software project was integrating PayPal Express Checkout NVP API operations. PayPal's API 238
  9. documentation is feeble, particularly when it comes to integrating the API with the Java programming language. This disturbed the flow of the application development process because we had to spend a lot of time learning and understanding the API integration for Java. Another challenge we faced during this project was the large size of the web application and everything was built from scratch. In the front-end part, we used the Bootstrap framework but there were a lot of things that still had to be tweaked by us. 5.3. Further improvements Although nearly all of the demands set for E-Commerce Web Applications have been met, there is still some room for improvement in the near future. A mobile application version can be developed to provide customers with a better experience. We consider adding more features to the system such as debit payment method, comments using images. The database of the system is quite modest, we plan to build up a bigger one. III. Conclusion Since large-scale systems are in high demand these days, software engineering is now based on other characteristics such as availability, ease of use, and scalability. In this paper, we have discussed how to develop an E-commerce website following the MVC architecture- Model, View, Controller, and DAO service. The development of this application was built on Eclipse IDE using Java programming language. We choose MySQL database to store the application data and TomCat 9.0 to run the server. This project's frontend is built with JSP (JavaServer Pages), which consists of HTML markup embedded with JSP tags, CSS for styling, and with the help of JavaScript client-side script to handle the UI logic. There are two major formats for the views (Admin role and Customer role). To handle the logic, each view component comes as a JSP page with JSP expressions, HTML, and sometimes even JavaScript or JSTL (Java Standard Tag Library). The resulting website- Lapeki E-Commerce, may not have been the quickest to develop, and performance may not be adequate for a large number of concurrent users yet, however, it demonstrated the architecture's power, which is total separation of front-end and back-end services. In the future, this project will develop to assure a high-level efficiency. Besides, more functionalities will be added considerably to increase the experience of customers. 239