A sample application for simple-jpa: laundry


The source code for this article can be found at https://github.com/JockiHendry/simple-jpa-demo-laundry

Griffon is a presentation layer framework for Java desktop-based application. This framework provides infrastructure to implement MVC pattern in desktop application. Griffon is best used with Groovy programming language although this may be subjective. In fact, Groovy is the default language for Griffon’s artifacts. Groovy is a Ruby-like dynamic programming language for Java platform. Example of Groovy’s cool features are closures (lambda expression) and metaprogramming. While it is a bit slower, code written in Groovy is much more straightforward and simpler than code written in old Java. But this may be changing in the future as the upcoming release of Java will introduce lambda expression.

Griffon is an application framework for presentation tier. Modern enterprise applications will likely have multiple tiers, such as presentation tier, business logic tier, and data access tier. In such architecture, Griffon based desktop application is the presentation tier. Presentation tier doesn’t have business logic. Instead, they invoke business logic in other tiers by using REST or SOAP. Griffon is doing a great job here.

Unfortunately, not all desktop applications are ‘thin client’. Some may want to access database and process the data directly. They have both presentation and business logic. While it is not attractive from the point of view of system architecture, ‘fat client’ is often effective for small organization with limited resources.

Does Griffon support fat desktop applications? Yes, in fact, Griffon supports a wide range implementation of desktop applications through its plugins. Griffon has a lot of plugins. For example, to create a desktop application that access database directly, we can use Griffon’s gsql plugin, hibernate4 plugin, jpa plugin, etc. And, of course, simple-jpa plugin is one of them. What is simple-jpa? It is something like JPA plugin but integrated deep into Griffon and exploits Groovy’s potential. simple-jpa is not a lightweight plugin. It has custom Swing’s nodes, validation and presentation of validation errors, scaffolding, and many mores. So, why use simple-jpa? Because it is the simplest way to create real life domain based desktop application in Griffon.

As a relatively new technology, can Groovy, Griffon and simple-jpa produce working application painlessly in real life? Yes, at least in my case! In this article, I’m introducing a sample application developed using these technologies. User interface and constants are declared using Bahasa Indonesia to reflect the requirements in my country. This sample application manages orders for laundry business. It records customers, orders and their status. Orders can be in one of the following states: received, in-progress, done, and delivered. To keep things simple, this sample application doesn’t include identity managements (login, user & privileges managements).

When user starts the application, Hibernate JPA will recreate database tables based on domain entities and executes griffon-app\resources\import.sql to populate tables with predefined data. This is configured in griffon-app\meta-inf\persistence.xml. Populating tables with predefined data every time application is launched makes manual testing become easy. Plugin simple-jpa also supports similar features for integration testing by using dbUnit but it is not used in this sample application.

Customer Screen

Customer Screen

Display Orders From Customer Screen

Display Orders From Customer Screen

There are two types of clients: corporate and outsider (or personal). User can filter customers by name or member type. They can also display orders details on selected customer. I use mvcPopupButton() node from simple-jpa to generate a JButton that will display another MVCGroup when clicked.

Order Screen

Order Screen

The add order view is quite complex. It has a button to select customer. This will invoke the same MVCGroup that is used to display customers in the previous menu.

Add Line Items From Order Screen

Add Line Items From Order Screen

One order has one or many line items. Clicking on the ‘add line items’ button will display another MVCGroup so user can add or edit line items here.

Find Job From Line Item View

Find Job From Line Item View

Every line item is associated with a job. Every job has a category (such as children, gentlemen, or ladies) and a job type (such as dry cleaning, laundry, or pressing). To help user in finding the right job, the sample application allow searching by job’s name, job’s category or job’s type. Another useful feature is that it will remember the last search criteria so user doesn’t need to enter the same search criteria in the next invocation.

Express Order Will Double The Cost

Express Order Will Double The Cost

Business rule states that express orders will double the cost (increase by 100%). So, if user checks on express checkbox, the total amount will be increased by 100%. There are also hidden text fields in this screen. When user selects one of the payment methods, new text fields will appear so he can enter required information. For example, if user selects credit card payment, he must enter credit card number. If user select signed bill payment, he must enter the amount of down payment.

Invoice Preview Will Be Displayed After Saving New Order

Invoice Preview Will Be Displayed After Saving New Order

When user clicks on save button, a preview window for invoice will be displayed. User can then print this invoice or save it as pdf file. The sample application use Jasper Reports to generate and preview all invoices and reports.

Order In-Progress Screen

Order In-Progress Screen

Delivery Screen

Delivery Screen

The last step of orders processing is delivery. This screen will display balance due. User can also click on status button to display more information about orders’ status.

Displaying Order Status Detail From Delivery Screen

Displaying Order Status Detail From Delivery Screen

History Screen

History Screen

The history screen will display all orders. User can search them by order number, customer’s name, or order’s state.

Day-End Closing Screen

Day-End Closing Screen

Day end closing menu will display daily total amount of cash, credit card or debit card transaction. User can use the values to confirm balance in cash drawer and card terminals for that day.

Selecting Report To Display

Selecting Report To Display

Filtering Data For Report

Filtering Data For Report

Reports

Reports

When user selects a report to display, he will be presented by a dialog where he can add filter criteria for that report.

Maintenance Menu

Maintenance Menu

Maintenance menu is an example of how to create drop down menu in Griffon.

That is a pretty long introduction. For convenience’ sake, the following class diagram shows domain classes in this sample application:

UML Class Diagram

UML Class Diagram

So, what’s next? Explore the code! See how Groovy, Griffon and simple-jpaplugin produces such a simple and easy to understand code. They will increase the agility of your project.

Perihal Solid Snake
I'm nothing...

Apa komentar Anda?

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: