[Request] Writabilitygate based on enumerated type?

6 posts / 0 new
Last post
Marc
Offline
Joined: 07/08/2009
[Request] Writabilitygate based on enumerated type?

Hi,

 

I successfully used writabiligates based on a boolean property to open or close the gate, via the class BooleanPropertyModelGate.

 

I now need propertyModelGates beased on an enumerated type. This means that the gate would be open when the property has one of the values out of a subset of values.

 

How to achieve this? Should we create a class EnumerationPropertyModelGate?

 

I had a look into the java code of BooleanPropertyModelGate. The method setModel is a bit complex and I thought that perhaps some code for BooleanPropertyModelGate and EnumerationPropertyModelGatemight be shared in a common superclass.

 

Is this all a good idea?

 

Thanks,

Marc

vvandens
Offline
Joined: 05/29/2008
[Request] Writabilitygate based on enumerated type?

HI Marc,

This is definitely a good idea.

But you could also simply define a computed boolean property (see the Employee age computed property in the reference manual to get the directions) for your component/entity that computes its value based on your business rule. Then, declare a boolean property gate on this computed property and you should be done.

 

Best,

Vincent

Marc
Offline
Joined: 07/08/2009
Vincent, the solution with

Vincent,

the solution with the computed property does not really solve my needs I think, for 2 reasons:

  1. I need multiple ones and hence I ultimately want to define the sets of values (determining when the gate is open/closed) from within Spring because hardcoding the values in Java does not sound a sufficient solution.
  2. The computed property would be a technical property that I need to hide from the user. I tried to hide a property using grantedroles without any roles. But this is apparently not sufficient to completely hide the property: it is still visible as a search criterion. So it seems that this extra property starts to add complexity.

Therefore I start to think that finally a writabilityGate on enumerated type may ultimately be a simpler solution. I could give it a try but I would end up with 80% same code as BooleanPropertyModelGate.

What do you think? Perhaps we have to consider immediately all types of gates, i.e. readabilitygates (see my other forum item: I do not fully understand readabilitygates yet)?

Thanks,
Marc

vvandens
Offline
Joined: 05/29/2008
EnumerationWritabillityGate

Marc,

I do agree with your arguments. Could you open a feature request for it and I will take care of implementing it with the necessary refactoring ?

BTW, a computed property should never apear as a search criterion... Could you open a bug for it ? You could also have defined queryableProperties on your entity to limit the properties used as search criterion.

Best,

Vincent

Marc
Offline
Joined: 07/08/2009
Vincent, feature request

Vincent,

feature request 2880635 opened.

Finally, a computed property does not appear as a search criterian. I did my test for hiding properties on a non-computed property, what explains my confusion. So no bug on that level.

Thanks,

Marc

vvandens
Offline
Joined: 05/29/2008
Done

Hi Marc,

I've created 2 new gates (and did the necessary refactoring) :

  • org.jspresso.framework.binding.model.EnumerationPropertyModelGate. Pass it a list of openingValues (the enumeration values for which you want the gate to open). You can still reverse the behaviour by setting openOnTrue=false.
  • org.jspresso.framework.binding.model.RegexPropertyModelGate. This one works on any string based value by opening based on a regex match (regexpPattern property). You can still reverse the behaviour by setting openOnTrue=false.

 

They are both included in the latest 3.0.1-SNAPSHOT. Make sure to read this important notice before going on.

 

Best,

Vincent