question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Entity with default validations rules, not correctly stored

See original GitHub issue
Overview of the issue

When generating an entity with default validations rules, this validation is not correctly stored in JSON.

Motivation for or Use Case

The result is a problem when exporting into JDL

Reproduce the error

Here the JSON:

{
    "fluentMethods": true,
    "relationships": [],
    "fields": [
        {
            "fieldName": "name",
            "fieldType": "String",
            "fieldValidateRules": [
                "minlength",
                "maxlength"
            ],
            "fieldValidateRulesMinlength": "5",
            "fieldValidateRulesMaxlength": "25"
        },
        {
            "fieldName": "age",
            "fieldType": "Integer",
            "fieldValidateRules": [
                "required",
                "min",
                "max"
            ],
            "fieldValidateRulesMin": 0,
            "fieldValidateRulesMax": "150"
        }
    ],
    "changelogDate": "20170629215405",
    "dto": "no",
    "service": "no",
    "entityTableName": "hello",
    "pagination": "no"
}

Here the JDL:

entity Hello (hello) {
  name String minlength(5) maxlength(25),
  age Integer required min max(150)
}
Related issues

Following the discussion here: https://github.com/jhipster/generator-jhipster/commit/8b1fd4ca9b68b978b61225fdc31c04fbc02f7c7f#commitcomment-22841709

Suggest a Fix

The problem comes directly from the JSON file. The entity should be saved with "0" instead of 0, but I didn’t find where…

All our entities in Travis samples are without "0" -> so need to be updated too

JHipster Version(s)
jhipster@0.0.0 /home/pgrimaud/tmp/21-default
└── generator-jhipster@4.5.6  -> /home/pgrimaud/projects/jhipster/generator-jhipster

JHipster configuration, a .yo-rc.json file generated in the root folder
{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "io.github.pascalgrimaud"
    },
    "jhipsterVersion": "4.5.6",
    "baseName": "jhipster",
    "packageName": "io.github.pascalgrimaud",
    "packageFolder": "io/github/pascalgrimaud",
    "serverPort": "8080",
    "authenticationType": "jwt",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "jwtSecretKey": "51ee67f57224be66bdf1598160e680d469d81ec2",
    "clientFramework": "angular2",
    "useSass": false,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": false
  }
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
entity Hello (hello) {
  name String minlength(5) maxlength(25),
  age Integer required min max(150)
}
Browsers and Operating System

java version “1.8.0_131” Java™ SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot™ 64-Bit Server VM (build 25.131-b11, mixed mode)

git version 2.9.3

node: v6.11.0

npm: 5.0.3

bower: 1.8.0

gulp: [00:43:36] CLI version 1.2.2

yeoman: 1.8.5

yarn: 0.24.5

Docker version 17.05.0-ce, build 89658be

docker-compose version 1.11.2, build dfed245

Execution complete

  • Checking this box is mandatory (this is just to show you read everything)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
deepu105commented, Jun 30, 2017

Seems when we manually type its captured as a string. May be we could cast the values to number always

Thanks & Regards, Deepu

On Fri, Jun 30, 2017 at 8:54 AM, Pascal Grimaud notifications@github.com wrote:

Here additional tests, I added some comments:

➜ jhe Burger Executing jhipster:entity Burger

The entity Burger is being created.

Generating field #1

? Do you want to add a field to your entity? Yes ? What is the name of your field? bigmac ? What is the type of your field? Integer ? Do you want to add validation rules to your field? Yes ? Which validation rules do you want to add? Minimum, Maximum ? What is the minimum of your field? 0 // <----- I type ENTER, let the default value ? What is the maximum of your field? 100 // <----- I type ENTER, let the default value

================= Burger ================= Fields bigmac (Integer) min=‘0’ max=‘100’

Generating field #2

? Do you want to add a field to your entity? Yes ? What is the name of your field? royalcheese ? What is the type of your field? Integer ? Do you want to add validation rules to your field? Yes ? Which validation rules do you want to add? Minimum, Maximum ? What is the minimum of your field? 0 // <------ I type manually 0 ? What is the maximum of your field? 100 <----- I type manually 100

================= Burger ================= Fields bigmac (Integer) min=‘0’ max=‘100’ royalcheese (Integer) min=‘0’ max=‘100’

Generating field #3

? Do you want to add a field to your entity? No

================= Burger ================= Fields bigmac (Integer) min=‘0’ max=‘100’ royalcheese (Integer) min=‘0’ max=‘100’

Generating relationships to other entities

? Do you want to add a relationship to another entity? No

================= Burger ================= Fields bigmac (Integer) min=‘0’ max=‘100’ royalcheese (Integer) min=‘0’ max=‘100’

? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly ? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly ? Do you want pagination on your entity? No

Everything is configured, generating the entity…

Here the result in JSON

➜ cat .jhipster/Burger.json { “fluentMethods”: true, “relationships”: [], “fields”: [ { “fieldName”: “bigmac”, “fieldType”: “Integer”, “fieldValidateRules”: [ “min”, “max” ], “fieldValidateRulesMin”: 0, “fieldValidateRulesMax”: 100 }, { “fieldName”: “royalcheese”, “fieldType”: “Integer”, “fieldValidateRules”: [ “min”, “max” ], “fieldValidateRulesMin”: “0”, “fieldValidateRulesMax”: “100” } ], “changelogDate”: “20170630065014”, “dto”: “no”, “service”: “no”, “entityTableName”: “burger”, “pagination”: “no”}

The 2 fieldValidateRulesMin are not consistent. One without double quote, one with.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jhipster/generator-jhipster/issues/6010#issuecomment-312190503, or mute the thread https://github.com/notifications/unsubscribe-auth/ABDlF_Bh32U9D71J6Q84_2ArFEkNNlNeks5sJJu3gaJpZM4OJ9Sq .

0reactions
pascalgrimaudcommented, Jul 14, 2017

I PR a fix in jhipster-core to fix the export-jdl. The other part about storing (capturing as a string and storing as a number) is really minor and isn’t necessary

Read more comments on GitHub >

github_iconTop Results From Across the Web

Restrict data input by using validation rules - Microsoft Support
To add validation rules to a table, you open the table and use commands on the Fields tab of the ribbon.
Read more >
7 Defining Validation and Business Rules Declaratively
Declarative validation rules are defined using the overview editor, and once created, are stored in the entity object's XML file. Declarative validation is ......
Read more >
The validation rule failed to enforce the business logic
- 1st one have to verify if "AccoundId" is populated (The validation rule should ONLY apply to contact records with an associated account)....
Read more >
Where to put global rules validation in DDD - Stack Overflow
It keeps the validation code in one place (implementation), and other code that depends on it will not have to change if the...
Read more >
Validation Rules | Mendix Documentation
You can only define validation rules for persistable entities as they are designed to ensure database integrity. Therefore, validation rules are ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found