This article shares an MDG Technology that integrates Sparx Enterprise Architect UML models with the free and open source JHipster RAD (Rapid Application Development) framework.
VISEO EA UML to JHipster Generator MDG produces JDL (JHipster Domain Language) content from UML models maintained in Enterprise Architect. This output can be used with JHipster to create the application's entities, including properties and relations.
Not being able to find a suitable tool that generates JHipster entities from UML models, I started such integration for a software application that has been implemented with JHipster 2. This work has been tested and used by VISEO JHipster experts and developers.
Update (31/10/2017): this project is now available from GitHub (MDG-Sparx-EA-UML-JHipster Github project) and will evolve to support new JHipster JDL definitions.
Note: a french version of this article is available here (version FR).
Context
A modelling project has been launched with Enterprise Architect to gather and maintain all the information and knowledge related with the project for the development team and stakeholders.
The initial models included business classes to identify the concepts, shared through a visual representation with UML. This approach has been useful when integrating these concepts in the technical environment JHipster.
JHipster, or “Java Hipster”, is a handy Open Source application generator that aims to create a complete and modern Web app, hence following a RAD approach:
- A high-performance and robust Java stack back-end (Spring Boot, Spring Security, Spring Data, Spring MVC, etc.)
- A sleek, modern, mobile-first front-end (Angular.js and Bootstrap)
- A suite of pre-configured development tools like Yeoman, Maven, Gradle, Grunt, Gulp.js and Bower
UML to JHipster JDL generator
Overview
Defining class models on both business and technical layers enabled a proper integration of the business definitions in the software application. Design workshops were carried in an efficient manner through the use of a common language and tool (Sparx Enterprise Architect and UML).
Looking for existing integration solutions between UML tools and JHipster yielded XMI exports/imports. However XMI implementations in UML tools don't provide most of the time a proper and full exchange of UML models i.e. without loss or modification of definitions. JDL Studio looked interesting; this online tool renders an entity diagram matching the JDL content. The downloaded file can be used to generate entities in JHipster (command line example: "yo jhipster:import-jdl export-jdl-uml.jh").
Without a suitable link between Enterprise Architect and JHipster, I wrote a script that generates such content directly from Enterprise Architect models. It requires the following JHipster 2 customizations carried in Enterprise Architect:
- Data types: JHipster types are available for the entities' attributes.
- UML profile: stereotypes on UML classes and attributes to provide JHipster properties via tagged values, listed below.
- Classes
- jhipsterDto : use mapstruct for the DTO-entity mapping
- jhipsterPaginate : pagination choice for lists (infinite-scroll, pager, pagination)
- jhipsterService : apply serviceClass to the entity
- Attributes
- jhipsterisRequired : the attribute is required
- jhipsterMin: provides the minimum value (declared as minlength for String attributes, or min for Integer, Long, Float, Double, or BigDecimal attributes)
- jhipsterMax: provides the maximum value (declared as maxlength for String attributes, or max for Integer, Long, Float, Double, or BigDecimal attributes)
- jhipsterPattern: provide the pattern value for a String attribute
- Script: generates the JDL content
- Classes
The following UML class diagram illustrates the meta-model applied for the UML to JHipster 2 JDL integration:
The script and UML profile have been improved through users' feedback and reviews from JHipster experts at VISEO.
Installation
The EA UML to JHipster MDG is published via an XML file. Once installed, it is listed in the MDG Technologies screen:
Note: this MDG is available from GitHub: MDG-Sparx-EA-UML-JHipster Github project. For any query, please contact me via e-mail: jhipster[at]umlchannel.com.
JHipster diagram and toolbox
EA/JHipster MDG Technology supports a diagram with its toolbox to create stereotyped classes and attributes:
UML profile and JHipster stereotypes
EA/JHipster MDG Technology includes a UML profile with stereotypes on classes and attributes to provide relevant Tagged Values.
When starting a JHipster design class diagram, JHipster entities contain tagged values available from the JHipster tab: DTO, paginate, service. The "none" value is set by default so all tagged values are optional.
The JHipster entity "Language" field is set to JHipster so its attributes are associated with the JHipster data types list.
The diagram toolbox can be used to add a stereotyped attribute to a JHipster Entity class. Such attributes also contains properties from the Tagged Values tab:
UML to JHipster generation script
The following UML class diagram has been defined with Sparx Enterprise Architect based on the JDL Studio example. This model provides a mean to check that the generated JDL content from either solution matches.
Compared with the JDL studio diagram, UML class diagrams have the advantage of being based on the OMG standard. Furthermore using a tool like Sparx Enterprise Architect provides a way to maintain the entity design model within a complete modelling repository e.g. including requirements, business, analysis and architecture models.
The following JDL content has been generated using this script:
=== EA UML to JHipster Entity Export ===
== More information is available from www.umlchannel.com/jhipster ==
INSTRUCTIONS: copy and paste the following content in a text file, and rename it e.g. as dpl.jh =
entity Department {
departmentId Long,
departmentName String required
}
entity JobHistory {
startDate ZonedDateTime,
endDate ZonedDateTime,
language Language
}
entity Job {
jobId Long,
jobTitle String,
minSalary Long,
maxSalary Long
}
/**
* The Employee entity.
*/
entity Employee {
employeeId Long,
/**
* The firstname attribute.
*/
firstName String,
lastName String,
email String,
phoneNumber String,
hireDate ZonedDateTime,
salary Long,
commissionPct Long
}
entity Location {
locationId Long,
streetAddress String,
postalCode String,
city String,
stateProvince String
}
entity Task {
taskId Long,
title String,
description String
}
entity Country {
countryId Long,
countryName String
}
entity Region {
regionId Long,
regionName String
}
enum Language {
FRENCH, ENGLISH, SPANISH
}
relationship OneToOne {
Department{location} to Location
}
relationship OneToMany {
/**
* A relationship
*/
Department{employee} to
/**
* Another side of the same relationship
*/
Employee
}
relationship OneToOne {
JobHistory{department} to Department
}
relationship OneToOne {
JobHistory{employee} to Employee
}
relationship OneToOne {
JobHistory{job} to Job
}
relationship ManyToMany {
Job{task(title)} to Task{job}
}
relationship ManyToOne {
Employee{manager} to Employee
}
relationship OneToMany {
Employee{job} to Job
}
relationship OneToOne {
Location{country} to Country
}
relationship OneToOne {
Country{region} to Region
}
paginate JobHistory, Employee with infinite-scroll
paginate Job with pagination
dto Job, Employee with mapstruct
service Employee with serviceClass
The final step involves copying this content to a JH file, and use it in JHipster to generate entities.
Scope
This approach was used as a mean to easily generate new versions of the design entity model within JHipster. Updates were carried in Enterprise Architect to remain consistent with the business model, whilst being generated, tested and approved directly in the application.
Once entities are updated in JHipster with custom code, it prevents any synchronization with the UML model. Where a full synchronization between the JHipster and UML projects is not the final purpose of this MDG, it allows having a design model that matches exactly the entities definition in the development environment during the first iterations of the project. This level of information in the design layer is very useful, even if mismatches with the code are bound to occur. The design team may chose to manually update the UML design model when needed.
Future versions
This MDG has been implemented and used with JHipster 2. A future version could be released to support new properties compatible with the latest JHipster release, such as:
- new serviceImpl service
- new syntax e.g. "dto (ou service ) * with … except …"
- skipClient and skipServer declaration on entities
- angularSuffix
- Microservices (e.g. microservice with <jhipster app name>)
- elasticsearch search on entities (e.g. search * with elasticsearch except …)
- New types (AnyBlob, ImageBlob)
- Generate minbytes and maxbypes for blob attributes( Blob, AnyBlob, ImageBlob)