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