How to extend JHipster JDL - jhipster

We would like to extend JDL to represent some additional GUI aspects in the generated frontend. E.g.:
show additional attributes from joined entities in the table
show custom defined attribute instead of entity ID in dropdowns
show detail list in parent entity form
etc.
Is there any way to extend JDL and use it in some custom blueprint? Or should we use some different approach?

In relation to the second item, there is a feature in the JDL relationship definition which helps:
relationship (OneToMany | ManyToOne | OneToOne | ManyToMany) {
<from entity>[{<relationship name>[(<display field>)]}] to <to entity>[{<relationship name>[(<display field>)]}]+
}
If you define one "display field" for the relationship end, JH will generate a drop-down using that field instead of the "id".
In relation to the third item, I am also interested in that feature. So, please let us know if you find a solution.

Related

Association without ReferenceVersionField

Is it possible to have a OneToManyAssociationField as entity extension on for example ProductManufacturer without the ReferenceVersionField in my related custom entity?
If this is not possible, is it possible for the reference version field to have a custom name (so not product_manufacturer_version_id) On first sight, this also does not seem possible.
About the error
I am currently getting the following error when trying to search for manufacturers using $criteria->addAssociation('myCustomEntity'):
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'product_manufacturer.myCustomEntity.product_manufacturer_version_id' in 'field list'
About the big picture
The use case is similar to the SeoUrl entity where there is a ‘foreign_key’ field which can have a relation to multiple entity types. My entity has not associations, but the other entities are extended to have an association to my entity. Just like the SeoUrl.
However, the DAL creates a query which uses the ‘product_manufacturer_version_id’ field, which does not exist on my custom entity…
Is it possible to have a OneToManyAssociationField as entity extension on for example ProductManufacturer without the ReferenceVersionField in my related custom entity?
No, you must set a ReferenceVersionField when adding associations to the definition of a versionized entity. This is too deeply rooted in the basic principles of the data abstraction layer to work around.
If this is not possible, is it possible for the reference version field to have a custom name (so not product_manufacturer_version_id) On first sight, this also does not seem possible.
You can change the storage name of the field. That is the name of the corresponding column within your database table. When you instantiate ReferenceVersionField you can use the second, optional argument to provide the storage name:
public function __construct(string $definition, ?string $storageName = null)
The storage name should be provided in snake case. The name of the object property for the field will then be derived from the storage name and converted to camel case. So given you provide my_version_custom_id for the storage name, the object property of the entity will be myVersionCustomId.
Your entity may have multiple associations to different entities, but if those entities are versionized your foreign key constraint has to be a combination of columns for both the foreign primary key as well as the foreign version id.

How to create one to many relationship using Liferay service builder

I need to define an one-to-many relationship between my custom entity and a Liferay default entity DDMFormInstance. So one MyCustomEntity could have many DDMFormInstance's. How can I do it?
you can define collection style columns; furthermore you will need a mapping-table between MyCustomEntity and DDMFormInstance and also remember that service-builder is not an ORM tool, primarily. so there will be a time when out-of-the-box functionalities will end.
<column entity="User" mapping-table="Users_Groups" name="users" type="Collection" />
see more in https://github.com/liferay/liferay-portal/blob/master/portal-impl/src/com/liferay/portal/service.xml
André's answer works by repurposing a many-to-many relationship as a one-to-many relationship. The challenge here is that DDMFormInstance is an out of the box Liferay entity, you cannot add a foreign key to it for the one-to-many relationship. André's answer is the easiest solution. You define a many-to-many relationship in the service.xml using mapping-table, then make it behave as one-to-many relationship in your MyCustomEntityLocalServiceImpl class.

What feature need to be enabled for entities filtering on Jhipster?

What those words "When this feature is enabled" on this documentation http://www.jhipster.tech/entities-filtering/ refer to ?
My jdl file is OK (thanks for the recent implemenattion : https://github.com/jhipster/generator-jhipster/issues/6286 )
Command jhipster import-jdl my_jdl_file.jdl work well.
But, I don't know what refer to "this feature" so it doesn't work (with swagger or postman).
Thanks
If you want to enable filtering in JDL you have to:
Use the filter keyword
Your entities must use a service class or implementation.
The sample JDL below will create the filter classes for entity A:
entity A
entity B
filter * except B
service * with serviceClass
If you generate your entities through the prompts, make sure to enable Service Class and Filtering options.
As an example with a Foo entity, in your foo.component.ts, you can add keys to the query object to filter on those fields:
this.fooService.query({ 'id.equals': 953 })
JDL Docs
Entity Filtering Docs

In JHipster how to create entity with relationship with User?

I need to create my own entities using the JHipster using the command "yo jhipster:entity myEntity" that have many-to-one relationship with the User entity that comes by default in JHipster.
I have tried unsuccessfully to create in the wizard a relationship with the entity "user" and the field "login" but it is not working.
What is the good way to do this with JHipster? Or do I have to create the entity without JHipster tool (but I need the CRUD!).
Thanks,
Yann
Just an update - jhipster 2.5.0 was released a few days ago adding support for this. Created this answer since the formatting in comments make i pretty hard to read.
When creating a relation for your entity simply answer the questions like this
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? user
? What is the name of the relationship? owner
? What is the type of the relationship? many-to-one
? When you display this relationship with AngularJS, which field from 'user' do you want to use? login
Possible values on how to display the relation could be: id, login, first_name, last_name, email
See https://jhipster.github.io/2015/03/01/jhipster-release-2.5.0.html for moreinformation
Just to add to the correct answer by #stoffer, if you're using the jdl it will look like:
relationship ManyToOne {
Owner{user(email)} to User{owner(name)}
}
at a good sample in an official document is say :
entity Blog {
name String required minlength(3),
handle String required minlength(2)
}
relationship ManyToOne {
Blog{user(login)} to User
}
jdl-samples/blog.jh
If you are using the 1.x version, this wasn't made to work, so basically you should do it by hand, without the generator (but it is definitely doable).
For the 2.x version, we have refactored the User object to have an ID field -> this should make this a lot easier, but as this is not released yet, we don't have a feedback at the moment.
I have come into this issue and solved it by using a simple one-to-one relationship first that will extend the user entity, because it is simple and manageable easily and can make the extended entity be the owner of the relationship, then you can create the many-to-one relationship with your entity, like this example:
entity MyEntity {
MyField Type
...
}
entity ApplicationUser {
additionalField Type
...
}
relationship OneToOne {
ApplicationUser{internalUser} to User
}
relationship ManyToOne {
MyEntity{appUser} to ApplicationUser{myEntities}
}
For more details and approach refer to this jHipster page.

Multiple similar entities or use the same one in core data?

So I've got a Client entity that needs a relationship to a PhoneNumber entity to allow multiple phone numbers. And I've got an Employee entity that also needs a relationship to a PhoneNumber entity to allow multiple phone numbers. Should I create two separate PhoneNumber entities or can I somehow use the same entity for both?
I would create a parent entity called Person for your Client and Employee entities. The Person entity would have a relationship to the PhoneNumber entity.
Inherited entities have the same attributes and relationships as their parent entity. Of course you can add attributes and relationships to the "child"-entities as well. I omitted that in the screenshot.
Something like this:
you can configure the parent entity in the core data inspector in the right side pane.

Resources