index.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. .. _community_wfsautopopulate:
  2. Features-Autopopulate Extension
  3. ===============================
  4. The Features Autopopulate plug-in listens to transactions (so far only issued by WFS), and autopopulates the feature type attributes according to the values retrieved from the properties file.
  5. The plugin uses a custom TransactionCallback that alters the insert/update WFS-T operations, forcing in specific values into them, based on configuration files.
  6. To support configuration for multiple layers, the easiest thing is to place a configuration, file in the directories of the layers themselves, pretty much like the :code:`featureinfo templates`.
  7. Assume that we want to allow GeoServer updating automatically two attributes of the :code:`topp:states` feature type every time we are going to perform an insert or update transaction.
  8. In particular what we want to do is:
  9. * Update/insert into the :code:`EDITOR` the current GeoServer user.
  10. * Update/insert into the :code:`LAST_UPDATE` the current timestamp
  11. We can leverage on two GeoServer :code:`CQL Expressions` that allow us to get thos values at runtime
  12. .. code-block:: ini
  13. EDITOR=env('GSUSER')
  14. LAST_UPDATE=now()
  15. The function :code:`env('GSUSER')` reads the system environment for a variable named :code:`GSUSER`, resolves the value and returns back the current logged-in username.
  16. This one is a special variable automatically created by GeoServer at :code:`login` time and injected into the local environment (see :code:`#EnviromentInjectionCallback` for more details)
  17. The function :code:`now()` gets the current timestamp and returns back the date-time.
  18. What we need to do then is to create a file named :code:`transactionCustomizer.properties` inside the folder :code:`$GEOSERVER_DATADIR/workspaces/topp/states` with the current key-value pairs
  19. .. code-block:: ini
  20. EDITOR=env('GSUSER')
  21. LAST_UPDATE=now()
  22. *NOTE*: The extension will look for the existing properties into the feature type. If no field matches the ones specified into the :code:`transactionCustomizer.properties`, the value will be ignored. The matches are *case-sensitive*.