Drools to decide fields to display in UI

53 Views Asked by At

I have a scenario where the fields in UI should be displayed based on User roles. For Example- If user is from role "A" then UI will display 5 fields but if the user is from role "B" then there will be 10 fields.

To accomplish the above design, I am thinking of using Drools rules engine. After user logs into the application, Frontend calls the API "/user/fields?Id=". The API first gets collection of field names and user role mappings from a DB table that is prepopulated and send all the mappings and logged in user's role to Drools. Drools will return the list of fields names matching the user's role and then send it to Frontend. Frontend is in Angular which will display or hide based on the lists.

I am using Java, Spring Boot for API and Angular for frontend. Is there a better approach or more efficient way of doing it?

2

There are 2 best solutions below

0
Roddy of the Frozen Peas On

Drools and other business rules engines are designed and best at handling complex decision trees. For trivially simple scenarios and applications, they tend to be out-performed by simple comparisons implemented in Java (eg. if/else trees.)

What you've described falls more on the "trivially simple" side of things. There's nothing in the proposed use case that indicates that you'd need or benefit from a business rules engine. Java 'if' statements will likely be more performant and require fewer resources and overhead.

0
Mike On

With 35K reputation you must have used Apache Camel which is just another Enterprise Integration Patterns implementation in java. What are good scenarios for Camel to use? - scenarios where EIP applicable...

Drools is just another Rete algorithm implementation in java. What are good scenarios for Drools to use? - scenarios where rete algorithm applicable.
The rete algorithm evaluates 'logic' differently than 'usual application'. When you have 10 properties involved and 'the logic' evaluates to false, in time, when one out of 10 properties change, rete algorithm is able to avaluate 'the logic' only for that single property that changed (the delta). Ordinal application would evaluate 'the whole logic' which is critical overhead for some type of applications.
For example, evaluation of traffic map route in live, when traffic conditions change or react on constant events coming from physical device.

This has similarities with how human mind 'works'. When we put socks in the morning we don't notice them during the day unless we get 'too cold' or 'too hot' events. The same is about reacting to things happened around, we 'react to the input that change with regard of the current knowledge' (we react on the 'delta'). This is why some make parallels with Drools and AI which is wrong in my opinion as main point of AI is about 'ability to learn or the logic to evolve'. Drools is about 'static logic'.

Drools implemented many more features 'to attract potential customers' and provide solution for 'demanding problems'. But IMHO Drools is first of all about that interesting rete algorithm specification.

Do you need that for security rules? If you want to learn Drools, this is possible to implement with Drools :)