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!
Advertisements

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.