Enterprise Architect version 13

download
purchase

English Chinese (Simplified) Czech Dutch French German Italian Korean Polish Portuguese Russian Slovak Spanish Swedish

My Profile

Social Media Channels

facebook google plus twitter youtube linkedin

Tuesday, 06 December 2016 21:13

MDG VISEO EA UML to JHipster Generator: generate JDL entities in JHipster from UML models

Written by 

VISEO EA UML to JHipster Generator MDG Technology

This article shares an MDG Technology that integrates Sparx Enterprise Architect UML models with JHipster.

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 in 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.

Note: the current version of the MDG is compatible with JHipster 2, latest available version when the project started. JHipster 3 new features could be integrated in a future version.

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:

  • 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 attribut 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

The following UML class diagram illustrates the meta-model applied for the UML to JHipster 2 JDL integration:

SparxSystems Enterprise Architect UML to JHipster JDL File generator metamodel

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:

MDG EA UML to JHipster JDL

Note: this MDG is available on request (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 to jhipster sparx en toolbox

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.

uml jhipster entity properties

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:

sparx ea uml attribute jhipster

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 JHipster 3 that has introduced new properties 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)

 

Read 1140 times Last modified on Thursday, 08 December 2016 23:19
Rate this item
(0 votes)
Guillaume

Guillaume Finance

VISEO (Modelling and Sparx EA Consultant & trainer)
 
Business and Systems Analyst with a software development background, and certified training instructor on UML, SysML and Sparx Enterprise Architect.
After spending several years working at an international level in the UK, I'm currently working for VISEO (formerly Objet Direct), Sparx Systems authorised reseller, VAR and Training Partner in France (www.viseo.com). Current and past projects cover the following industries: banking & finance (e.g. mortgage application), payment card systems (ATM, POS, UK APACS, ISO8583), set-top boxes, oil and gaz, and hydraulic utility manufacturing (EDF).
I publish articles and news about modelling languages and Enterprise Architect on my blog www.umlchannel.com.
I also maintain eaUtils addin for Sparx: www.eautils.com.

Website: www.umlchannel.com
Login to post comments