Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

Commit

Permalink
Implemented the jpaMetamodelFiltering option
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuAA committed Aug 28, 2017
1 parent e7699e1 commit fd8f712
Show file tree
Hide file tree
Showing 16 changed files with 1,494 additions and 1,216 deletions.
3 changes: 2 additions & 1 deletion lib/core/jhipster/unary_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const UNARY_OPTIONS = {
SKIP_CLIENT: 'skipClient',
SKIP_SERVER: 'skipServer',
SKIP_USER_MANAGEMENT: 'skipUserManagement',
NO_FLUENT_METHOD: 'noFluentMethod'
NO_FLUENT_METHOD: 'noFluentMethod',
FILTER: 'filter',
};

function exists(option) {
Expand Down
22 changes: 22 additions & 0 deletions lib/dsl/grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
searchEngine: {},
noClient: { list: [], excluded: [] },
noServer: { list: [], excluded: [] },
filter: { list: [], excluded: [] },
angularSuffix: {},
noFluentMethod: { list: [], excluded: [] }
};
Expand Down Expand Up @@ -125,6 +126,10 @@ prog
parsed.noFluentMethod = noFluentMethod;
return parsed;
}
/ SPACE* filter:filterDecl SPACE* p:prog {
parsed.filter = filter;
return parsed;
}
/ '' { return parsed; }

// Application Declaration
Expand Down Expand Up @@ -451,6 +456,22 @@ subNoServerDecl
/ ALL { return ['*']; }
/ e:ENTITY_NAME { return [e]; }

// JPA Metamodel filter option
filterDecl
= FILTER SPACE decl:subFilterDecl SPACE* ex:exclusion? SPACE* {
addUniqueElements(parsed.filter.list, decl);
if (ex) {
addUniqueElements(parsed.filter.excluded, ex);
}
return parsed.filter;
}

subFilterDecl
= e:ENTITY_NAME SPACE* ',' SPACE* sub:subFilterDecl { return addUniqueElements([e], sub); }
/ STAR { return ['*']; }
/ ALL { return ['*']; }
/ e:ENTITY_NAME { return [e]; }


// angularSuffix option
angularSuffixDecl
Expand Down Expand Up @@ -567,6 +588,7 @@ SEARCH = 'search'
SKIP_CLIENT = 'skipClient'
SKIP_SERVER = 'skipServer'
ANGULAR_SUFFIX = 'angularSuffix'
FILTER = 'filter'
// validations
REQUIRED = 'required'
MINLENGTH = 'minlength'
Expand Down
1,964 changes: 1,088 additions & 876 deletions lib/dsl/pegjs_parser.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions lib/parser/entity_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function initializeEntities() {
dto: 'no',
pagination: 'no',
service: 'no',
jpaMetamodelFiltering: false
};
}
}
Expand Down Expand Up @@ -133,6 +134,9 @@ function setEntityNamesOptions(option) {
case BinaryOptions.ANGULAR_SUFFIX:
entities[entityName].angularJSSuffix = option.value;
break;
case UnaryOptions.FILTER:
entities[entityName].jpaMetamodelFiltering = true;
break;
default:
entities[entityName][option.name] = option.value;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/parser/jdl_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ function fillUnaryOptions() {
excludedNames: document.noFluentMethod.excluded
}));
}
if (document.filter.list.length !== 0) {
jdlObject.addOption(new JDLUnaryOption({
name: UnaryOptions.UNARY_OPTIONS.FILTER,
entityNames: document.filter.list,
excludedNames: document.filter.excluded
}));
}
}

function addOption(key, value) {
Expand Down
11 changes: 11 additions & 0 deletions test/spec/parser/entity_parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,16 @@ describe('::convert', () => {
);
});
});
describe('when converting a JDL with filtering', () => {
const input = parseFromFiles(['./test/test_files/filtering.jdl']);
const content = EntityParser.parse({
jdlObject: JDLParser.parse(input, 'sql'),
databaseType: 'sql'
});
it('converts it', () => {
expect(content.A.jpaMetamodelFiltering).to.be.true;
expect(content.B.jpaMetamodelFiltering).to.be.false;
});
});
});
});
8 changes: 8 additions & 0 deletions test/spec/parser/jdl_parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,14 @@ describe('JDLParser', () => {
expect(application.skipServer).to.be.false;
});
});
describe('when parsing filtered entities', () => {
const input = parseFromFiles(['./test/test_files/filtering.jdl']);
const content = JDLParser.parse(input, 'sql');
it('works', () => {
expect(content.options.options.filter.entityNames.has('*')).to.be.true;
expect(content.options.options.filter.excludedNames.has('B')).to.be.true;
});
});
});
});
});
4 changes: 4 additions & 0 deletions test/test_files/filtering.jdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
entity A
entity B

filter * except B
75 changes: 38 additions & 37 deletions test/test_files/jhipster_app/.jhipster/Country.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
{
"fluentMethods": true,
"relationships": [
{
"relationshipType": "one-to-one",
"relationshipName": "region",
"otherEntityName": "region",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "country"
},
{
"relationshipType": "one-to-one",
"relationshipName": "user",
"otherEntityName": "user",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "country"
}
],
"fields": [
{
"fieldName": "countryId",
"fieldType": "Long",
"javadoc": "The country Id"
},
{
"fieldName": "countryName",
"fieldType": "String"
}
],
"changelogDate": "20160926101210",
"entityTableName": "country",
"dto": "no",
"pagination": "no",
"service": "no",
"skipClient": true,
"skipServer": true
"fluentMethods": true,
"relationships": [
{
"relationshipType": "one-to-one",
"relationshipName": "region",
"otherEntityName": "region",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "country"
},
{
"relationshipType": "one-to-one",
"relationshipName": "user",
"otherEntityName": "user",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "country"
}
],
"fields": [
{
"fieldName": "countryId",
"fieldType": "Long",
"javadoc": "The country Id"
},
{
"fieldName": "countryName",
"fieldType": "String"
}
],
"changelogDate": "20160926101210",
"entityTableName": "country",
"dto": "no",
"pagination": "no",
"service": "no",
"jpaMetamodelFiltering": false,
"skipClient": true,
"skipServer": true
}
79 changes: 40 additions & 39 deletions test/test_files/jhipster_app/.jhipster/Department.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
{
"fluentMethods": true,
"relationships": [
{
"relationshipType": "one-to-one",
"relationshipName": "location",
"otherEntityName": "location",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "department"
},
{
"relationshipType": "one-to-many",
"relationshipValidateRules": "required",
"relationshipName": "employee",
"otherEntityName": "employee",
"javadoc": "A relationship",
"otherEntityRelationshipName": "department"
}
],
"fields": [
{
"fieldName": "departmentId",
"fieldType": "Long"
},
{
"fieldName": "departmentName",
"fieldType": "String",
"fieldValidateRules": [
"required"
]
}
],
"changelogDate": "20160926092246",
"entityTableName": "department",
"dto": "no",
"pagination": "no",
"service": "no",
"skipClient": true,
"skipServer": true
"fluentMethods": true,
"relationships": [
{
"relationshipType": "one-to-one",
"relationshipName": "location",
"otherEntityName": "location",
"otherEntityField": "id",
"ownerSide": true,
"otherEntityRelationshipName": "department"
},
{
"relationshipType": "one-to-many",
"relationshipValidateRules": "required",
"relationshipName": "employee",
"otherEntityName": "employee",
"javadoc": "A relationship",
"otherEntityRelationshipName": "department"
}
],
"fields": [
{
"fieldName": "departmentId",
"fieldType": "Long"
},
{
"fieldName": "departmentName",
"fieldType": "String",
"fieldValidateRules": [
"required"
]
}
],
"changelogDate": "20160926092246",
"entityTableName": "department",
"dto": "no",
"pagination": "no",
"service": "no",
"jpaMetamodelFiltering": false,
"skipClient": true,
"skipServer": true
}
Loading

5 comments on commit fd8f712

@DanielFran
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this can be used directly from jdl and jdl-studio?

@MathieuAA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I release a new version, which isn't right now as we're migrating from PegJS to Chevrotain.

@agoncal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MathieuAA Still not merged I'm afraid ? Any plans to release this soon ?

@MathieuAA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agoncal Hello. Yeah, tonight as a matter of fact I intend to release a patch or a minor version.

@agoncal
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MathieuAA you are the best !

Please sign in to comment.