.. _smart_data_loader_data_store:
Smart Data Loader
=================
Data Store
----------
In addition to the parameters common to each ``DataStore`` configuration such as ``workspace``, ``name`` and ``description``, the page shows the following connection parameters in the dedicated section:
* ``Data store name``: the name of the PostGIS ``DataStore`` already created under the same workspace. It will be used to access the database and build xsd and mappings file based on the database metadata.
* ``Root entity``: the name of the DB table to be used as the root FeatureType to build the xsd and the mapping file.
Once selected the root entity a diagram of the entities available will appear. Uncheck the attributes that should not be included in the XSD and the mapping file.
Meteo Stations example
----------------------
This section provides an example of configuring the ``DataStore`` with weather station information.
.. note:: This example is intended to be illustrative of a general approach, and does not reflect a formally defined schema or information model. Also, more complicated scenarios may require significantly more work.
A diagram of the entities involved is shown below:
.. figure:: images/stations-diagram.png
Entities diagram
As shown, the dataset consists of:
* A One to Many relationship between the ``meteo_stations`` and ``meteo_observations`` tables.
* A Many to Many relationship between the ``meteo_stations`` and ``meteo_maintainers`` tables, mapped by the relation table ``meteo_stations_maintainers``.
* A Many to One relationship between the ``meteo_observations`` and the ``meteo_parameters`` tables.
Assuming a PostGIS datastore named meteos-simple under the st workspace, by opening the Smart Data Loader page we will have to select the desired workspace and the postgis datastore belonging to the selected workspace, in this case the meteos-postgis one:
.. figure:: images/store-page.png
Smart Data Loader configuration page
After having selected the root entity as meteo-stations, a schema, which will be used to generate the XSD and mappings file, will appear. Each attribute/entity can be unchecked to avoid it being included in the generated mappings.
..figure:: images/store-relations.png
Smart Data Loader configuration page - entities' tree
After pressing the save button, the files will be generated automatically in the store data-dir directory under ``app-schema-mappings`` directory.
The generated mappings file for this example are explained below.
GML schema definition::
App-Schema mappings file::
gml
http://www.opengis.net/gml/3.2
st
http://www.stations.org/1.0
./meteo_stations-gml.xsd
smartappschematest
meteo_stations
st:MeteoStationsFeature
st:MeteoStationsFeature
strConcat('MeteoStationsFeature.',id)
st:id
id
st:code
code
st:common_name
common_name
st:position
position
meteoObservations
FEATURE_LINK[1]
st:MeteoObservationsFeature
id
meteoStationsMaintainers
FEATURE_LINK[1]
st:MeteoStationsMaintainersFeature
id
smartappschematest
meteo_observations
st:MeteoObservationsFeature
FEATURE_LINK[1]
station_id
st:MeteoObservationsFeature
strConcat('MeteoObservationsFeature.',id)
st:id
id
st:time
time
st:value
value
meteoParameters
FEATURE_LINK[1]
st:MeteoParametersFeature
parameter_id
smartappschematest
meteo_parameters
st:MeteoParametersFeature
FEATURE_LINK[1]
id
st:MeteoParametersFeature
strConcat('MeteoParametersFeature.',id)
st:id
id
st:param_name
param_name
st:param_unit
param_unit
smartappschematest
meteo_stations_maintainers
st:MeteoStationsMaintainersFeature
FEATURE_LINK[1]
station_id
st:MeteoStationsMaintainersFeature
strConcat('MeteoStationsMaintainersFeature.',id)
st:id
id
meteoMaintainers
FEATURE_LINK[1]
st:MeteoMaintainersFeature
maintainer_id
smartappschematest
meteo_maintainers
st:MeteoMaintainersFeature
FEATURE_LINK[1]
id
st:MeteoMaintainersFeature
strConcat('MeteoMaintainersFeature.',id)
st:id
id
st:name
name
st:surname
surname
st:company
company
smartappschematest
schema
smartappschematest
database
mock?sslmode=DISABLE&binaryTransferEnable=bytea
port
5432
passwd
postgres
Expose primary keys
true
dbtype
postgis
host
localhost
user
postgres
Customize smart-data-loader generated mappings and xsd definition
------------------------------------------------------------------
The Smart Data Loader does not allow direct modification of the mappings and XSD type definition. However it can be used as a starting point to generate configuration files that can be customized as required.
This is the suggested workflow for such a use case:
* Create a new smart-data-loader store, select the desired PostGIS store, and then the root entity and save it.
* Go to the geoserver datadir and identify the Smart Data Loader store folder under the workspace that was selected while configuring it. An ``app-schema-mappings`` directory should be in that store folder.
* Copy and paste the files contained in that directory to another directory and modify them as needed.
* Delete the Smart Data Loader store, and create a new App-Schema store with a uri parameter pointing to the folder containing the modified files.