Sample project using Plain JavaSE – Episode 4

Hi, this is the fourth post of a series where i’ll be publishing some samples showing how to develop web applications with Java technology.
This post sample consists on a project ‘staffgest-mvc-freemarker‘ that serves as presentation layer using Freemarker.

This web app is deployed on a embedded Glassfish server .
You can read more about Glassfish Embedded in here.
You can read more about Freemarker in here.
For more context please refer to the previous post.

The proposed flow on the web application  is:

  1.  Visit – ‘localhost:8080/staffgest-mvc-freemarker/new-employee.html’ , where a form to create an employee is showed
    – submit form and “new-employee.ftl” is rendered
  2. Visit – ‘localhost:8080/staffgest-mvc-freemarker/search-employee.html’ , where a form to search an employee is showed
    – submit form and “search-employee.ftl” is rendered

Relevant code snippets:

Web.xml

Controller

Views
“new-employee.html”

“new-employee.ftl”

“search-employee.html”

“search-employee.ftl”

staffgest-mdw‘ , ‘staffgest-mvc-freemarker‘ – are all maven projects, so it should be fairly simple to import and build it. First build “staffgest-mdw” and the run “staffgest-mvc-freemarker” through a main class ‘App.java’.
Hope it’s helpful for someone!

Advertisements

Sample project using Plain JavaSE – Episode 3

Hi, this is the third post of a series where i’ll be publishing some samples showing how to develop web applications with Java technology.
This post sample consists on a project ‘staffgest-persistence-hibernate-jpa‘ that serves as persistence layer using JPA.
I’ll use Hibernate 5 as a JPA provider and H2 as an in-memory relational database.

On the next episode i’ll plug this project as a dependency on ‘staffgest-mdw‘.

You can read more about JPA in here.
You can read more about Hibernate in here.
You can read more about H2 in here.

For more context please refer to the previous post.

Relevant code snippets:

Persistence.xml
https://gist.github.com/arthurportas/a7fed5a33b69ae1023ea2d250cee1077

Generic DAO interface
https://gist.github.com/arthurportas/020083d56a8b840eabec350c30b7fb83

Generic DAO interface
https://gist.github.com/arthurportas/020083d56a8b840eabec350c30b7fb83

Generic DAO Impl
https://gist.github.com/arthurportas/bcf2cfa0baa221ce351fa1890f4b3f40

Employee DAO Interface
https://gist.github.com/arthurportas/76054e17b43edea4f04fbdff3e82abb7

Employee DAO Impl
https://gist.github.com/arthurportas/525e43b01aecdd780c6a234226da6f26

Employee DAO Tests
https://gist.github.com/arthurportas/fde2b404ba6c7acdcc0cff4c81b0a406

staffgest-persistence-hibernate-jpa‘  – is a maven project, so it should be fairly simple to import and build it.
Hope it’s helpful for someone!

Sample project using Plain JavaSE – Episode 2

Hi, this is the second post of a series where i’ll be publishing some samples showing how to develop web applications with Java technology.
This post sample consists on a project ‘staffgest-jsf‘ that serves as presentation layer using JSF.

This web app is deployed on a embedded Glassfish server .
You can read more about Glassfish Embedded in here.
You can read more about JSF in here.
For more context please refer to the previous post.

The proposed flow on the web application  is:

  1.  Visit – ‘localhost:8080/staffgest-mvc-jsp/new-employee.xhtml’ , where a form to create an employee is showed
    – submit form and “new-employee-result.xhtml” is rendered
  2. Visit – ‘localhost:8080/staffgest-mvc-jsp/search-employee.xhtml’ , where a form to search an employee is showed
    – submit form and “search-employee-result.xhtml” is rendered

Relevant code snippets:

JSF configuration on web.xml
https://gist.github.com/arthurportas/020083d56a8b840eabec350c30b7fb83

Employee Backing Bean
https://gist.github.com/arthurportas/0a2e6bfc8f834144a14cbc47f025d4dd

Views
“new-employee.xhtml”
https://gist.github.com/arthurportas/b726d951faf0c9b380601fc0bd20a12b

“new-employee-result.xhtml”
https://gist.github.com/arthurportas/1d0ad841517f6714fed8764cb318e145

“search-employee.xhtml”
https://gist.github.com/arthurportas/20393e1abb5524657bdae77632bbd3cd

“search-employee-result.xhtml”
https://gist.github.com/arthurportas/a274c18566805c4e3b1bdaab95b3b866

staffgest-mdw‘ ,  ‘staffgest-jsf‘  – are all maven projects, so it should be fairly simple to import and build it. First build “staffgest-mdw” and the run “staffgest-jsf” through a main class ‘App.java’.
Hope it’s helpful for someone!

 

Sample project using Plain JavaSE – Episode 1

Hi, this is the initial post of a series where i’ll be publishing some samples showing how to develop web applications with Java technology.
I’ll try to start with a very simple example and make some progress visiting several APIs/Application Servers  from the JEE stack.
This post sample consists on three projects that only uses POJOs.
The adopted subject is an application with codename ‘staffgest’ with employee management APIs.

The adopted architecture consists on a base project -”staffgest-mdw” that has the middleware service layer and the persistence layer(very simple, in memory List).
Through our journey, i’ll be decoupling the persistence layer and the presentation layer for demonstration purposes.
I’ll deliver two sample projects – “staffgest-text” and “staffgest-mvc-jsp” having the presentation layer for -”staffgest-mdw”.
“staffgest-text” is a JSE console app and”staffgest-mvc-jsp” is a web app deployed on a embedded Glassfish server .
You can read more about Glassfish Embedded in here.

The proposed flow on the web application  is:

  1.  Visit – ‘localhost:8080/staffgest-mvc-jsp/new-employee.html’ , where a form to create an employee is showed
    – submit form and “new-employee.jsp” is rendered
    Feedback welcome!
  2. Visit – ‘localhost:8080/staffgest-mvc-jsp/search-employee.html’ , where a form to search an employee is showed
    – submit form and “search-employee.jsp” is rendered

Relevant code snippets:

Controller

Views
“new-employee.html”

“new-employee.jsp”

“search-employee.html”

“search-employee.jsp”

staffgest-mdw‘ ,  ‘staffgest-text‘ , ‘staffgest-mvc-jsp‘ – are all maven projects, so it should be fairly simple to import and build it. First build “staffgest-mdw” and the run “staffgest-text” or “staffgest-mvc-jsp” through a main class ‘App.java’.
Hope it’s helpful for someone!

Sample project using Spring Boot, MongoDB(Fongo) with a scheduled maintenance job and test repository with NoSqlUnit

Hi, this is the another post of a series where i’ll be publishing some samples showing how to work with MongoDB documents with Java.
This post sample consists on a project that uses spring-boot with spring-data-mongo repository, Fongo(an in-memory mongodb representation) and a schedule maintenance job to delete user records.
We will also use NoSqlUnit – a helper library for tests.
For a cleaner document object, we use Lombok.

You can read more about scheduling-tasks in here.

This project uses the same structure of the one in my previous post.

User document.

User repository.

Scheduled tasks.

Configuration.

At this point we can run the app and what the logs to see the scheduled job in action.

captura-de-ecra%cc%83-2017-01-28-as-19-50-48

Having the app running if we run the test ‘testCountAllUsersNotUpdatedOnLast24Hours’
we can check that all users from the dataset ‘five-users.json’ are loaded and when the schedule job runs it deletes all the five records. All records have the property ‘lastUpdated’ with values that exceed more than 24 hours from now.

Sample data to load using NoSqlUnit.

Sample test.

 Logs.
captura-de-ecra%cc%83-2017-01-28-as-20-05-42
 captura-de-ecra%cc%83-2017-01-28-as-20-07-32
fongo-scheduled-job‘ – is a maven project, so it should be fairly simple to import and build it.
Hope it’s helpful for someone!

Sample project using Spring Boot and MongoDB(Fongo) and test repository with NoSqlUnit

Hi, this is the initial post of a series where i’ll be publishing some samples showing how to work with MongoDB documents with Java.
This post sample consists on a project that uses spring-boot with spring-data-mongo repository, Fongo(an in-memory mongodb representation) and NoSqlUnit – a helper library for tests.
For a cleaner document object, we use Lombok.

You can read more about Fongo in here.
You can read more about NoSqlUnit in here.
You can read more about Spring-data-mongo in here.
You can read more about Lombok in here.

User document.

User repository.

Sample data to load using NoSqlUnit.

Sample test.

Configuration

fongo-hello-world‘ – is a maven project, so it should be fairly simple to import and build it. Run the test on class ‘UserRepositoryTest’.
Hope it’s helpful for someone!

Sample project using JasperReports to generate pdf documents

Hi, this is the initial post of a series where i’ll be publishing some samples showing how to generate pdf documents with the popular library JasperReports using the Java API.

You can read more about JasperReports in here.
Pdf document templates were designed with iReport Designer

Sample code to generate blank pdf document.

Project samples:

*All running tests create a pdf document in the hard-coded path set and hang the current java process.While the process is running you can preview the pdf with your favourite tool.
When you stop this process, the document is deleted. This is the behaviour.

jasperreports-hello-world-pdf‘ – is the simplest sample where a blank pdf is generated. Run the main class ‘JasperReportsApplication’ and adjust the directory where the pdf file is created to fit your environment.

jasperreports-pdf-image‘ – this sample shows how to insert an images in several ways inside a pdf.
Run the tests declared in ‘ImageIT’ and adjust the directory where the pdf file is created to fit your environment.

jasperreports-pdf-table‘ – this sample shows how to fill a table with data inside a pdf using a ‘JRBeanCollectionDataSource’.
Run the test in ‘TableIT’ and adjust the directory where the pdf file is created to fit your environment.