Editing : how to not allow empty values ?

29 views
Skip to first unread message
Assigned to surendhar.d...@geosolutionsgroup.com by lorenzo...@geosolutionsgroup.com

Maël REBOUX

unread,
Sep 30, 2022, 5:50:29 AM9/30/22
to mapstor...@googlegroups.com

Hello.

 

I'm experiencing problems  while configuring a custom FeatureEditor.

 

The context :

Set up a mapstore context dedicated to manage datas by users. So the layers in this MS2 context are updatable by WFS-T transaction.

We want to strictly control the data edition by setting up database constraints and MS2 editor constraints.

 

In the PostgreSQL / PostGIS database we have :

 

CREATE TABLE espace_public.arbre (

    id serial NOT NULL

  , code_insee varchar(5) NOT NULL

  , id_secteur text NULL

  , nom_commun text NOT NULL DEFAULT 'Non renseigné'

  , nom_taxon text NOT NULL DEFAULT 'Non renseigné'

  , complement text NULL

  , fonction text NULL DEFAULT 'Non renseignée'

  , type_taille text NULL DEFAULT 'Non renseigné'

  , classe_biodiv text NULL

  , diag_sanitaire text NULL DEFAULT 'Non renseigné'

  , etat_physiologique text NULL DEFAULT 'Non renseigné'

  , etat_mecanique text NULL DEFAULT 'Non renseigné'

  , fiche_diagnostic text NULL

  , date_plantation date NULL

  , date_diagnostic date NULL

  , date_entretien date NULL

  , frequence_entretien integer NULL

  , date_proch_entretien date NULL

  , date_fin date NULL

  , date_maj date NOT NULL

  , geom geometry NOT NULL

);

 

-- contraintes sur la géométrie

ALTER TABLE espace_public.arbre ADD CONSTRAINT enforce_srid_geometry CHECK (st_srid(geom) = 3948) ;

ALTER TABLE espace_public.arbre ADD CONSTRAINT enforce_dims_geometry CHECK (st_ndims(geom) = 2) ;

ALTER TABLE espace_public.arbre ADD CONSTRAINT enforce_geotype_geometry CHECK (geometrytype(geom) = 'POINT'::text) ;

 

-- clé primaire et indexes

ALTER TABLE espace_public.arbre ADD CONSTRAINT arbres_pk PRIMARY KEY (id) ;

CREATE INDEX arbres_idx_geom ON espace_public.arbre USING gist (geom) ;

 

-- contraintes de valeurs

-- fonction

ALTER TABLE espace_public.arbre ADD CONSTRAINT type_fonction_dom CHECK (fonction::text = ANY ('{"Non renseignée","Alignement","Ornement","Totem","Verger","Ripisylve"}'::text[]));

-- type_taille

ALTER TABLE espace_public.arbre ADD CONSTRAINT type_taille_dom CHECK (type_taille::text = ANY ('{"Non renseigné","Structurée","Cépée","Port libre","Trogne","Demi-tige","Autre"}'::text[]));

-- diag_sanitaire

ALTER TABLE espace_public.arbre ADD CONSTRAINT diag_sanitaire_dom CHECK (diag_sanitaire::text = ANY ('{"Non renseigné","A - Sain","B – Moyen","C – Dégradé","D - À couper"}'::text[]));

-- etat_physiologique

ALTER TABLE espace_public.arbre ADD CONSTRAINT etat_physiologique_dom CHECK (etat_physiologique::text = ANY ('{"Non renseigné","A","B","C","D","E"}'::text[]));

-- etat_mecanique

ALTER TABLE espace_public.arbre ADD CONSTRAINT etat_mecanique_dom CHECK (etat_mecanique::text = ANY ('{"Non renseigné","A","B","C","D","E"}'::text[]));

 

 

As you can see : an INSERT INTO query with a NULL value on the "nom_commun" attribute will insert a 'Non renseigné' value. Because we do not want null or empty string here.

 

 

On the 2.17 GeoServer :

Nothing special : read and write rules are ok on this layer.

WFS-T is working well.

 

 

In the MS2 context, in the FeatureEditor plugin I put this JSON configuration (a part only) :

 

{

    "cfg": {

        "editingAllowedRoles": [

            "ADMIN",

            "USER",

            "EL_MAJ_INTERCO"

        ],

        "customEditorsOptions": {

            "rules": [{

                    "regex": {

                        "attribute": "nom_commun",

                        "typeName": "test:arbre"

                    },

                    "editor": "DropDownEditor",

                    "editorProps": {

                        "allowEmpty": false,

                        "defaultOption": "Non renseignée"

                    }

                }, {

                    "regex": {

                        "attribute": "fonction",

                        "typeName": "test:arbre"

                    },

                    "editor": "DropDownEditor",

                    "editorProps": {

                        "allowEmpty": false,

                        "forceSelection": true,

                        "values": [

                            "Non renseignée", "Alignement", "Ornement", "Totem", "Verger", "Ripisylve"

                        ],

                        "defaultOption": "Non renseignée"

                    }

                }

            }

            ]

        }

    },

    "override": {}

    }

 

But it does not prevent the user to create new records with empty strings :

 

 

 

Just click on the "Save record" button and the result is :

 

 

 

 

The database let him go because MS2 create an empty string value and not a NULL value.

 

 

What is the trick to not let user send blank / empty string values ?

Is the  "allowEmpty": false directive not working ?

 

 

 

Maël REBOUX
Service Information Géographique Rennes Métropole
Chargé de mission données et diffusion

02 99 86 63 71

Twitter : @mael_reboux_ig

 

image005.jpg
image006.jpg

Lorenzo Natali

unread,
Oct 12, 2022, 3:47:58 AM10/12/22
to mapstore-users
Hi,
the custom editors do not validate the input. In particular the DropDown editor only give a constraint on the value inserted. 
In fact "allowEmpty" do not influences string values, because WFS-T and GeoServer do not distinguish between a NULL value and an empty string.  
For the string values you should set forceSelection and defaultOption, but as I said, it doesn't do a validation on the content before to send, it only assists the user on editing, forcing a selection or setting the default one.
Validate the values to allow/deny the save and maybe suggest the invalid fields could be a good addition for the Feature Editor plugin. 

Anyway looks strange to me that the creation is allowed. 

CHECK (type_taille::text = ANY ('{"Non renseigné","Structurée","Cépée","Port libre","Trogne","Demi-tige","Autre"}'::text[]));

This constraint on the database should deny the insertion of empty values. Isn't it?

m.re...@rennesmetropole.fr

unread,
Nov 7, 2022, 4:39:54 AM11/7/22
to mapstore-users
Well.
This is dissapointing yes.

I have to turn the database in verbose log mode to understand what is going.
I come back after.
Reply all
Reply to author
Forward
0 new messages