Git Product home page Git Product logo

eclipse-ee4j / cargotracker Goto Github PK

View Code? Open in Web Editor NEW
339.0 23.0 138.0 82.37 MB

The project demonstrates how you can develop applications with Jakarta EE using widely adopted architectural best practices like Domain-Driven Design (DDD).

Home Page: https://eclipse-ee4j.github.io/cargotracker/

License: MIT License

Java 25.23% HTML 5.45% CSS 2.24% JavaScript 67.07% Dockerfile 0.01%
javaee jakartaee domain-driven-design ddd java

cargotracker's Introduction

Eclipse Cargo Tracker - Applied Domain-Driven Design Blueprints for Jakarta EE

The project demonstrates how you can develop applications with Jakarta EE using widely adopted architectural best practices like Domain-Driven Design (DDD). The project is directly based on the well known original Java DDD sample application developed by DDD pioneer Eric Evans' company Domain Language and the Swedish software consulting company Citerus. The cargo example actually comes from Eric Evans' seminal book on DDD. The original application is written in Spring, Hibernate and Jetty whereas the application is built on Jakarta EE.

The application is an end-to-end system for keeping track of shipping cargo. It has several interfaces described in the following sections.

For further details on the project, please visit: https://eclipse-ee4j.github.io/cargotracker/.

A slide deck introducing the fundamentals of the project is available on the official Eclipse Foundation Jakarta EE SlideShare account. A recording of the slide deck is available on the official Jakarta EE YouTube account.

Eclipse Cargo Tracker cover

Getting Started

The project website has detailed information on how to get started.

The simplest steps are the following (no IDE required):

  • Get the project source code.
  • Ensure you are running Java SE 11 or Java SE 17.
  • Make sure JAVA_HOME is set.
  • As long as you have Maven set up properly, navigate to the project source root and type:
mvn clean package cargo:run

This will run the application with Payara Server by default. The project also has Maven profiles to support GlassFish and Open Liberty. For example you can run using GlassFish using the following command:

mvn clean package -Pglassfish cargo:run

Similarly you can run using Open Liberty using the following command:

mvn clean package -Popenliberty liberty:run

To set up in Visual Studio Code, follow these steps:

  • Set up Java SE 11, or Java SE 17, Visual Studio Code and Payara 6. You will also need to set up the Extension Pack for Java and Payara Tools in Visual Studio Code.
  • Make sure JAVA_HOME is set.
  • Open the directory that contains the code in Visual Studio Code. Visual Studio Code will do the rest for you, it will automatically configure a Maven project. Proceed with clean/building the application.
  • After the project is built (which will take a while the very first time as Maven downloads dependencies), simply run the generated cargo-tracker.war file under the target directory using Payara Tools.

You can similarly use GlassFish or Open Liberty in Visual Studio Code.

Exploring the Application

After the application runs, it will be available at: http://localhost:8080/cargo-tracker/. Under the hood, the application uses a number of Jakarta EE features including Faces, CDI, Enterprise Beans, Persistence, REST, Batch, JSON Binding, Bean Validation and Messaging.

There are several web interfaces, REST interfaces and a file system scanning interface. It's probably best to start exploring the interfaces in the rough order below.

The tracking interface let's you track the status of cargo and is intended for the general public. Try entering a tracking ID like ABC123 (the application is pre-populated with some sample data).

The administrative interface is intended for the shipping company that manages cargo. The landing page of the interface is a dashboard providing an overall view of registered cargo. You can book cargo using the booking interface. Once cargo is booked, you can route it. When you initiate a routing request, the system will determine routes that might work for the cargo. Once you select a route, the cargo will be ready to process handling events at the port. You can also change the destination for cargo if needed or track cargo.

The Handling Event Logging interface is intended for port personnel registering what happened to cargo. The interface is primarily intended for mobile devices, but you can use it via a desktop browser. The interface is accessible at this URL: http://localhost:8080/cargo-tracker/event-logger/index.xhtml. For convenience, you could use a mobile emulator instead of an actual mobile device. Generally speaking cargo goes through these events:

  • It's received at the origin location.
  • It's loaded and unloaded onto voyages on it's itinerary.
  • It's claimed at it's destination location.
  • It may go through customs at arbitrary points.

While filling out the event registration form, it's best to have the itinerary handy. You can access the itinerary for registered cargo via the admin interface. The cargo handling is done via Messaging for scalability. While using the event logger, note that only the load and unload events require as associated voyage.

You should also explore the file system based bulk event registration interface. It reads files under /tmp/uploads. The files are just CSV files. A sample CSV file is available under src/test/sample/handling_events.csv. The sample is already set up to match the remaining itinerary events for cargo ABC123. Just make sure to update the times in the first column of the sample CSV file to match the itinerary as well.

Sucessfully processed entries are archived under /tmp/archive. Any failed records are archived under /tmp/failed.

Don't worry about making mistakes. The application is intended to be fairly error tolerant. If you do come across issues, you should report them.

You can simply remove ./cargo-tracker-data from the file system to restart fresh. This directory will typically be under $your-payara-installation/glassfish/domains/domain1/config.

You can also use the soapUI scripts included in the source code to explore the REST interfaces as well as the numerous unit tests covering the code base generally. Some of the tests use Arquillian.

Exploring the Code

As mentioned earlier, the real point of the application is demonstrating how to create well architected, effective Jakarta EE applications. To that end, once you have gotten some familiarity with the application functionality the next thing to do is to dig right into the code.

DDD is a key aspect of the architecture, so it's important to get at least a working understanding of DDD. As the name implies, Domain-Driven Design is an approach to software design and development that focuses on the core domain and domain logic.

For the most part, it's fine if you are new to Jakarta EE. As long as you have a basic understanding of server-side applications, the code should be good enough to get started. For learning Jakarta EE further, we have recommended a few links in the resources section of the project site. Of course, the ideal user of the project is someone who has a basic working understanding of both Jakarta EE and DDD. Though it's not our goal to become a kitchen sink example for demonstrating the vast amount of APIs and features in Jakarta EE, we do use a very representative set. You'll find that you'll learn a fair amount by simply digging into the code to see how things are implemented.

Cloud Demo

Cargo Tracker is deployed to Kubernetes on the cloud using GitHub Actions workflows. You can find the demo deployment on the Scaleforce cloud (https://cargo-tracker.j.scaleforce.net). This project is very thankful to our sponsors Jelastic and Scaleforce for hosting the demo! The deployment and all data is refreshed nightly. On the cloud Cargo Tracker uses PostgreSQL as the database. The GitHub Container Registry is used to publish Docker images.

Jakarta EE 8

A Jakarta EE 8, Java SE 8, Payara 5 version of Cargo Tracker is available under the 'jakartaee8' branch.

Java EE 7

A Java EE 7, Java SE 8, Payara 4.1 version of Cargo Tracker is available under the 'javaee7' branch.

Contributing

This project complies with the Google Style Guides for Java, JavaScript, and HTML/CSS. You can use the google-java-format tool to help you comply with the Google Java Style Guide. You can use the tool with most major IDEs such as Eclipse, Visual Studio Code, and IntelliJ.

In general for all files we use a column/line width of 80 whenever possible and we use 2 spaces for indentation. All files must end with a new line. Please adjust the formatting settings of your IDE accordingly. You are encouraged but not required to use HTML Tidy and CSS Tidy to help format your code.

For further guidance on contributing including the project roadmap, please look here.

Known Issues

  • When using Visual Studio Code, please make sure that the JAVA_HOME environment variable is correctly set up. If it is not configured properly, you will be unable to select a domain when adding a Payara Server instance in Visual Studio Code.
  • When using Visual Studio Code, please make sure that Payara is not installed in a path with a space (for example: C:\Program Files\payara6). Payara will fail to start with the Payara Tools extension. Install Payara on a path without spaces (for example: C:\payara6).
  • Presently, Jakarta EE 10 and Payara 6 encounters operational challenges within Eclipse IDE. Consequently, we have adopted Visual Studio Code as an alternative. We wholeheartedly welcome contributions aimed at rectifying the compatibility disparity within Eclipse IDE. Your input towards resolving this issue would be greatly appreciated.
  • You may get a log message stating that Payara SSL certificates have expired. This won't get in the way of functionality, but it will stop log messages from being printed to the IDE console. You can solve this issue by manually removing the expired certificates from the Payara domain, as explained here.
  • If you restart the application a few times, you will run into a bug causing a spurious deployment failure. While the problem can be annoying, it's harmless. Just re-run the application (make sure to completely un-deploy the application and shut down Payara first).
  • Sometimes when the server is not shut down correctly or there is a locking/permissions issue, the H2 database that the application uses get's corrupted, resulting in strange database errors. If this occurs, you will need to stop the application and clean the database. You can do this by simply removing the cargo-tracker-data directory from the file system and restarting the application. This directory will typically be under $your-payara-installation/glassfish/domains/domain1/config.
  • While running with Open Liberty, you will notice a number of spurious errors. You will see shrinkwrap features warnings, message-driven bean warnings, the AggregateObjectMapping nested foreign key warning, I/O errors, etc. You can safely ignore these. They don't affect the application functionality.

cargotracker's People

Contributors

alexmario74 avatar dependabot[bot] avatar dmatej avatar dmuelle avatar ggam avatar gkwan-ibm avatar gurunrao avatar hantsy avatar ibrahimdoss avatar kasabuta4 avatar m-reza-rahman avatar ndacyayisenga-droid avatar nishantraut avatar ocseal avatar ojuschugh1 avatar ondromih avatar thadumi avatar yashtef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cargotracker's Issues

Add Jakarta EE Feature Recommendations section

Add a section explaining higher level Java EE feature choices and recommendations as they pertain to the application (e.g. annotations vs. XML). Need to maintain a balance since API/feature best practices are not the primary focus (as opposed to architectural blueprints/patterns) and the application would not cover large parts of many APIs (as perhaps the samples do).

Alternatively, create API specific sub-projects (or altogether separate projects perhaps leveraging this code base) that focus on technology feature choices/best practices (e.g. best practices for WebSocket, JAX-RS, JPA, EJB, JMS, etc).

Demonstrate solution for lazy-loading

In the application some JPA relations are one-to-many and by default lazy loaded. When fetching the aggregate-root through the repository the returned root object will be detatched. Eclipselink handles this for read operations but Hibernate would throw a LazyInitializationException.

A traditional solution would be to add methods to a DAO such as loadCargoWithLoadedLegs();
With a lot of lazy collections and many combinations this would quickly be a bloated interface.

As a developer I would like to fetch the root, access and make changes to any object in graph, then store the root and have all changes persisted.

Unable to set cargo as "CLAIMED" or "RECEIVED"

When I tried an end to end use-case, I was able to do event logging of "LOAD", "UNLOAD" for a route.
But, when I do "CLAIM" at the destination, the status change does not happen and the application's dashboard (admin view)
does not show the cargo-item in "claimed" category.

Integrate WebSocket

The current idea is to create a live dashboard with drill-down capabilities showing the location and status of cargo across the globe (and possibly voyage routes).

The problem is that this will use "SSE" only so only a partial use of WebSocket. Other ideas welcome. Chat seems a bit too artificial.

JSF warn message displayed on details of a cargo

Steps to reproduce :

Administrative landing page
Click on Tracking ID ABC123

=> JSF warn message : "The metadata component needs to be nested within a f:metadata tag. Suggestion: enclose the necessary components within <f:metadata>"

Environment

Netbeans 8.0
Glassfish 4.0
JDK 7

Support for different databases

It would be nice to be able to get the application to work with different databases. It doesn't seem to be trivial to get the application to work with Oracle XE for example.

Cargotracker won't cleanly undeploy and redeploy

Usually, when I undeploy the cargotracker application, the following error appears in the server log:

SEVERE: The web application [/cargo-tracker] created a ThreadLocal with key of type [org.glassfish.pfl.dynamic.codegen.impl.CurrentClassLoader$1] (value [org.glassfish.pfl.dynamic.codegen.impl.CurrentClassLoader$1@18df5b39]) and a value of type [org.glassfish.web.loader.WebappClassLoader] (value [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

I can then clean the project. Rebuilding generally succeeds the first time, too. But when I try to run it, deployment fails. Here is the relevant info from the server log:

INFO: Loading sample data.
INFO: Unloading all existing data.
SEVERE: Exception while invoking class org.glassfish.ejb.startup.EjbApplication start method
javax.ejb.EJBException: javax.ejb.CreateException: Initialization failed for Singleton SampleDataGenerator
...
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.

I have to stop and restart the database and server to be able to run the app again.

mvn cargo:run throws error on Ubuntu 12

As described in https://java.net/projects/cargotracker/pages/Home#Getting_Started all one needs to do is run the 'mvn cargo:run' command to start the application. I checked out the cargo-tracker source from SVN, and ran 'mvn cargo:run' which downloaded the dependencies, started the glassfish server, but then failed with FileNotFound exception saying that unable to find the cargo-tracker.war file.

I therefore had to run 'mvn package' to create the cargo-tracker.war. After which, 'mvn cargo:run' started the application successfully.

Would be good if we can either fix this as a doc comment or in the deployment, for folks using Ubuntu.

Thanks,
Rahul.

Environment

Ubuntu 12

Rerouting a Cargo to its destination raise an Exception

'Book Cargo' refuse to book a cargo that has the same Origin and Dest ("Origin and destination cannot be the same").
But this following case is not handled correctly:

  • "Book Cargo" : A to B
  • "Change Destination" : B to A (the cargo has now A as both Origin & Dest).
    -> EJB Exception Caused by: java.lang.IllegalArgumentException: Origin and destination can't be the same: Chicago [USCH

Design Alternatives - Anti Corruption Layer for Graph Traversal Service

The two main contexts for the CargoTracker Application are the Booking context and the Routing Context. So when the Booking context makes a call to the Routing context via the External Routing Service, it can be done via a separate facade and a translator rather than putting it all into the External Routing Service itself. This helps us change the implementation of the facade if the routing context offers a different protocol for connecting or requires certain additional features for the default protocol supplied.

This Anti Corruption Layer comprises of the Service, the Connector facade and translator and is a possible variant to the open host context relationship. Illustration provided in the attached diagram

Provide more details when 'registration failed'

When logging an event failed, the only message sent to the user is "registration failed". Is this failure due a domain issue or to a technical issue?
User need to get more useful feedback.

Put application on cloud

Figure out a way to save data only per session (multitenacy?). Which cloud service should we use?

uses consistent date format

Some dates uses dd/mm/yyyy (show.xhtml) while others are using yyyy-mm-dd (e.g. incident-logger.xhtml)

Environment

Mac OS X (english with BE local)

POM unloadable in NetBeans

When I open the project (from the SVN repository) in NetBeans 7.3.1, I get the following error:

Some problems were encountered while processing the POMs: [ERROR] 'dependencies.dependency.version' for org.jboss.arquillian.junit:arquillian-junit-container:jar is missing. @line 62, column 21.

This problem is resolved by adding the version number 1.1.0.Final to the arquillian-junit-container dependency element of the POM.

Environment

Windows 7, NetBeans 7.3.1

Livemap need to handle 'unknown location'

Cargo with last location set to unknown are displayed in the middle of the USA.
Either don't display them or display them in a 'parked' area (eg. bottom left)

Environment

NA

uses consistent date format

Some dates uses dd/mm/yyyy (show.xhtml) while others are using yyyy-mm-dd (e.g. incident-logger.xhtml)

Environment

Mac OS X (english with BE local)

Document JSF mapping decision

In web.xml, for a Facelets index.xhtml, it is customary to list the welcome file as follows:

faces/index.xhtml

And the servlet-mapping is usually

/faces/*

not

*.xhtml

I can assign myself to this issue and make the fixes if there is no objection.

Validating date when booking a cargo

When booking a cargo, if the date is not valid, the application should display an nice jsf message.

Instead, it redirects on the details of the new cargo but this new cargo is not displayed in the list.

Environment

JDK 1.7
Netbeans 8.0
Glassfish 4.0

HTML namespaces in Facelets pages need updating for Java EE 7 (JSF 2.2)

As of JavaServer Faces 2.2, the namespace URLs for Facelets pages have changed from java.sun.com to xmlns.jcp.org. To support Java EE 7, for example, the three middle namespaces in the following html element in admin/registration.xhtml need to be fixed:

The last one, which is used for the JSF 2.2 pass-through elements feature, is already correct.

The old namespaces are still supported, so you don't get errors. But EE 7 apps should use the new ones.

NullPointerException when booking a new cargo

Steps to reproduce :

Administrative landing page
Tab "Booking"
Try to book a cargo with any origin, any destination and any arrival deadline (valid one)

=> javax.faces.el.EvaluationException: java.lang.NullPointerException: Country and location may not be null

Environment

Netbeans 8.0
Glassfish 4.0
JDK 7.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.