Testing JDL Studio for JHipster application
The newest version of JHipster gives us an opportunity to generate backbone model in 3 different ways. Today we will test the fastest one 🙂 JHipster since version 4.x provided great tool which creates the World a better place. This tool is JDL Studio available here. You can prototype there whole models at once and generate it everytime you would like to.
Spis treści
Available data types
You can prototype your classes with defined below types of fields. Relational and non-relational databases sometimes have different types, just remember about it.
entity <entity name> { <field name> <type> [<validation>*] }
SQL | MongoDB | Cassandra | Validations |
---|---|---|---|
String | String | String | required, minlength, maxlength, pattern |
Integer | Integer | Integer | required, min, max |
Long | Long | Long | required, min, max |
BigDecimal | BigDecimal | BigDecimal | required, min, max |
Float | Float | Float | required, min, max |
Double | Double | Double | required, min, max |
Enum | Enum | required | |
Boolean | Boolean | Boolean | required |
LocalDate | LocalDate | required | |
Date | required | ||
ZonedDateTime | ZonedDateTime | required | |
UUID | required | ||
Blob | Blob | required, minbytes, maxbytes | |
AnyBlob | AnyBlob | required, minbytes, maxbytes | |
ImageBlob | ImageBlob | required, minbytes, maxbytes | |
TextBlob | TextBlob | required, minbytes, maxbytes |
Relationships
Available are all relationships: 1:1, 1:n, n:1, m:n. You can always choose if any of those relations is bidirectional or unidirectional.
relationship <type> { <from entity>[{<relationship name>}] to <to entity>[{<relationship name>}] }
Enumerations and blobs
They are also available, what can I say more 😉 You can also define some constant values (like PI) and use it in entity model.
enum <enum name> { <enum values> }
Option declaration
In JHipster you can specify options for entities such as generating pagination, service or DTO. Example from docs:
entity A { name String required } entity B {} entity C {} dto A, B with mapstruct paginate A, C with infinite-scroll paginate B with pager service A with serviceClass service C with serviceImpl
Error handling
Web interface returns errors on the top of the schema and shows red stripe on the left. If you use wrong syntax, it will try to show what is expected, how should looks like and – for me the most important – which line has failed. Remember, that you shouldn’t leave commas a the end of enumeration of class parameters 😉
Example JDL Studio
entity City { name String } enum Fee { FREE, PAID } entity Series { name String, description String, organizer String } entity Topic { name String } entity Event { name String, description String, startDate LocalDate, endDate LocalDate, language String, fee Fee, place String, address String, registerationLink String, eventWww String } relationship OneToMany { City{city} to Event{event}, Series{series} to Event{event}, Event{event} to Topic{topic} } paginate City, Series, Event, Topic with pagination dto Event with mapstruct dto Topic with mapstruct service Event with serviceClass service Topic with serviceClass
How the generated schema model looks like?
Next time we will be generating these data into EventSearch application. We will use magic command:
yo jhipster:import-jdl .jhipster\input.jh