greycat icon indicating copy to clipboard operation
greycat copied to clipboard

Validation of values

Open DataWorm opened this issue 7 years ago • 1 comments

Hi,

it would be nice to have a feature for value validation. So whenever a value is set on the model there should be a way to verify if this value is legal. For common types like non-negative numbers, non-empty strings, non-nullpointers there could be some predefined annotations. For more complex validation it might be nice to be able to add own validator-implementations.

Example:

class Tabular {
  att rows : Integer
  att columns : Integer
  rel cellValues : String
}

Let's say I have that table and I wanna make sure that there are no more than rowscolumns values in the cellValues-List. Or maybe I want to make it more restrictive to force it being exactly rowscolumns entries but the missing ones filled with a default value. But I guess this restriction should be something like a post-processing step instead of a validation as it needs to modify content as soon as table dimensions get changed.

Another question that just came to my mind when i made this simplified example: In that case of a table I have like a ordered list or an array of values. The index of those values inside the list matters and often you probably would like to change the value at a specific index. Does that work easily with the generated code or do I have to rebuild that list myself in correct order myself? Sorry if that is a stupid question but due to limited access to pc/internet I can't try it out myself atm. =)

DataWorm avatar Sep 15 '17 14:09 DataWorm

We already have an Enfocer for attribute type, but can be a good idea to extend the modeling layer with them: https://github.com/datathings/greycat/blob/e3db7314b0e83b598201641c0854be963a30f552/greycat/src/main/java/greycat/utility/Enforcer.java cc: @thomashartmann

assaad avatar Sep 15 '17 14:09 assaad