Pular para o conteúdo principal

JavaEE, JavaFX and RFID - Part 1: The Application


Hello! Today I'm going to show how is easy to create a JavaFX application that integrates with a RFID reader. Specifically with the RFID Starter Kit.

It's a complete application that reads a RFID tag and then search information about it on a remote database accessed through a REST interface. To avoid an extensive blog post, I divided it in 4 parts:

Part 1: The Application
Part 2: Reading RFID from Java
Part 3: REST API and Security
Part 4: The Client

The application

We will demonstrate the use of RFID with JavaFX using a simple Application where a person with  will pass a card on a RFID reader and our application will give more information about the person, or if the person is in the database.
The application also allows you to register a new person, delete existing people and modify information.
The app will basically work as demonstrated on the following diagram:


 The Application Database


The database contains person information and also the RFID related to it and we give roles to this person, so we can authorize the person(if needed).









We also have a table to add administrators that can access this database information:










Our application is responsible to guarantee that only authorized users can access and change the information in the database. As you can see, the table person has a column for the RFID tag and the client application will be simple responsible to read it and access the person information using a REST API.

Accessing the data from Java using JPA

We use Java to access the database. Our final application will be in a WAR deployed in an application server (I'll talk more about it on the next post) that implements JEE 6 specification, and one of the famous JEE specification is JPA, that allow us to handle database information.
To set the application persistence we need to have the persistence.xml file, which is the descriptor  responsible to declare general JPA configuration. See persistence.xml.

Notice it refers to a Datasource, the application server we will use is Wildfly and datasources can be declared using *-ds.xml. Deployable datasources can be placed in the WEB-INF directory of our WAR. In our application we have the  people-ds.xml, that we configure to access the default filesystem based database that comes with Wildfly. Code of both XMLs:

Now our application is ready to access a database and to have access to it from Java, we created model objects and we use JPA annotations in order to declare the database correspondence with our Java class. See Person.java source code.
Finally, to handle this information, we use a class named EntityManager in our PersonService Stateless EJB class.

Now we are ready to expose our DB information through a REST interface. But it's a subject for the next post ;)

See Complete Source code of the WEB module

Conclusion

We presented our application modeling and the database access. It's a simple application, however, we will briefly cover all technologies used to create it. Next part we will talk about the REST interface and how we secure it.

Comentários

Postagens mais visitadas deste blog

Simplest JavaFX ComboBox autocomplete

Based on this Brazilian community post , I've created a sample Combobox auto complete. What it basically does is: When user type with the combobox selected, it will work on a temporary string to store the typed text; Each key typed leads to the combobox to be showed and updated If backspace is type, we update the filter Each key typed shows the combo box items, when the combobox is hidden, the filter is cleaned and the tooltip is hidden:   The class code and a sample application is below. I also added the source to my personal github , sent me PR to improve it and there are a lot of things to improve, like space and accents support.

Dancing lights with Arduino - The idea

I have been having fun with Arduino these days! In this article I am going to show how did I use an electret mic with Arduino to create a Dancing Lights circuit. Dancing Lights   I used to be an eletronician before starting the IT college. I had my own electronics maintenance office to fix television, radios, etc. In my free time I used to create electronic projects to sell and I made a few "reais" selling a version of Dancing lights, but it was too limited: it simply animated lamps using a relay in the output of a 4017 CMOS IC. The circuit was a decimal counter  controlled by a 555. 4017 decimal counter. Source in the image When I met Arduino a few years ago, I was skeptical because I said: I can do this with IC, why should I use a microcontroller. I thought that Arduino was for kids. But now my pride is gone and I am having a lot of fun with Arduino :-) The implementation of Dancing Lights with Arduino uses an electret mic to capture the sound and light leds...

Creating custom Work Item Handler in BPM Suite/jBPM 6

Hi all! In this post I am going to share my experience creating a work item handler for BPM Suite 6.0.3 (which is very similar to jbpm as explained in a previous post ). The Hello World Work Item Handler Let's create a really simple WorkItemHandler just to print "Hello World" in the console. Of course you can implement more feature and make it receive parameters, access database, web services, etc. But in this post we will keep it simple. Really simple. First thing to do is to create a maven project for my WorkItemHandler. Here's the pom.xml of my Maven project: Notice that we are importing jbpm dependency so we can find the java interface that is used to create work item handlers. Now we can start coding. Let's create a class name HelloWorkItemHandler in package org.jugvale.jbpm, here is the simple code: Now we can build our project and go to BPM Suite to configure it so we can use this workitem. Registering the WorkItemHandler UPDATE...