Puppet Class: ckan::ext::spatial

Defined in:
manifests/ext/spatial.pp

Summary

Installs the "spatial" extension.

Overview

Allows for the association of datasets with geographic locations, and for searches across datasets to be restricted to a particular geographical area. Additionally, it provides some support for previewing geographical datasets.

Parameters:

  • template (String)

    The name the template that spatial will modify. Note, this will overwrite the following files:

    • templates/package/search.html

    • templates/package/read_base.html

  • map_provider (String) (defaults to: 'default')

    Which map provider to use. Options:

    • ‘default’ - removes older configuration which may not work with newer versions of ckanext-spatial.

    • ‘openstreetmap’ - the older settings which may not work due to cross-origin error.

    • ‘mapquest’ - depricated, do not use

    • ‘custom’ - uses a custom type that requires the map_url parameter.

  • map_type (Optional[String]) (defaults to: undef)

    Depricated, no longer used.

  • map_url (Optional[String]) (defaults to: undef)

    The tileset URL. This follows the Leaflet URL template format ( z for zoom and x y for tile coordinates)

  • map_attribution (Optional[String]) (defaults to: undef)

    The attribution for the map tiles and license. This expects html formatting for urls like <a href=></a>.

  • default_extent (Optional[String]) (defaults to: undef)

    Sets the default extent for the map. Should be a string in the format:

    “‘ ’[[15.62, -139.21], [64.92, -61.87]]‘ “`

    or GeoJSON
    

    “‘ ’{ "type":

    \"Polygon\", \"coordinates\": [[[74.89, 29.39],[74.89, 38.45], [60.50,
    38.45], [60.50, 29.39], [74.89, 29.39]]]}'
    ```
    

    If undefined, will not set an extent.

  • non_extra_spatial (Boolean) (defaults to: false)

    Set to false if the spatial field is not in the extra dictionary.

  • revision (Optional[String]) (defaults to: undef)

    The version of spatial to install.

  • add_spatial_search_widget (Boolean) (defaults to: true)

    True if the spatial search should be added and false otherwise.

See Also:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'manifests/ext/spatial.pp', line 60

class ckan::ext::spatial (
  String           $template,
  String           $map_provider              = 'default',
  Optional[String] $map_type                  = undef,
  Optional[String] $map_url                   = undef,
  Optional[String] $map_attribution           = undef,
  Optional[String] $default_extent            = undef,
  Boolean          $non_extra_spatial         = false,
  Optional[String] $revision                  = undef,
  Boolean          $add_spatial_search_widget = true,
) {
  $package_root = "${ckan::ckan_ext}/ckanext-${template}/ckanext/${template}/templates/package"
  $search       = "${package_root}/search.html"
  $read_base    = "${package_root}/read_base.html"

  if $default_extent {
    $use_default_extent = true
  } else {
    $use_default_extent = false
  }

  # check for OS version
  if $facts['os']['release']['full'] == '12.04' or $facts['os']['release']['full'] == '14.04' {
    $required_packages = [
      'libxml2-dev',
      'libxslt1-dev',
      'libgeos-c1',
    ]
  } else {
    $required_packages = [
      'libxml2-dev',
      'libxslt1-dev',
      'libgeos-c1v5',
    ]
  }

  ensure_packages($required_packages)

  # check if need to install external libraries for solr
  if $ckan::solr_schema_version == 'spatial-ext' {
    solr::shared_lib { 'jts':
      url     => $ckan::jts_url,
      require => Class['solr'],
    }
    solr::shared_lib { 'mmseg4j':
      url     => 'https://repo1.maven.org/maven2/com/chenlb/mmseg4j/mmseg4j-solr/2.4.0/mmseg4j-solr-2.4.0.jar',
      require => Class['solr'],
    }
    $backend = 'solr-spatial-field'
  } else {
    $backend = 'solr'
  }

  postgresql_psql { 'init_db_spatial':
    db      => 'ckan_default',
    command => 'create extension postgis',
    unless  => 'select * from pg_extension where extname=\'postgis\'',
    require => Postgresql::Server::Database['ckan_default'],
  }

  postgresql_psql { 'init_db_topology':
    db      => 'ckan_default',
    command => 'create extension postgis_topology',
    unless  => 'select * from pg_extension where extname=\'postgis_topology\'',
    require => Postgresql_psql['init_db_spatial'],
  }

  postgresql::server::grant { 'schema_grant_all':
    privilege   => 'ALL PRIVILEGES',
    object_type => 'SCHEMA',
    object_name => 'topology',
    db          => 'ckan_default',
    role        => 'ckan_default',
    require     => Postgresql_psql['init_db_topology'],
  }

  postgresql::server::grant { 'grant_all_tables':
    privilege   => 'ALL PRIVILEGES',
    object_type => 'ALL TABLES IN SCHEMA',
    object_name => 'topology',
    db          => 'ckan_default',
    role        => 'ckan_default',
    require     => Postgresql::Server::Grant['schema_grant_all'],
  }

  ckan::ext { 'spatial':
    plugin    => ['spatial_metadata', 'spatial_query'],
    run_setup => true,
    revision  => $revision,
    require   => Postgresql::Server::Grant['grant_all_tables'],
  }

  ckan::conf::setting { 'ckanext.spatial.search_backend':
    value   => $backend,
  }

  # ensure the package directory exists
  file { $package_root:
    ensure  => directory,
    #require => Package['python-ckan'],
    require => File['/usr/lib/ckan/default/src'],
  }

  # add spatial search widget
  if $add_spatial_search_widget {
    file { $search:
      ensure  => file,
      content => template('ckan/ext/search.html.erb'),
      require => File[$package_root],
    }
    file { $read_base:
      ensure  => file,
      content => epp('ckan/ext/read_base.html.epp',{
          non_extra_spatial => $non_extra_spatial
      }),
      require => File[$search],
    }
  }

  case $map_provider {
    'default' : {
      ckan::conf::setting { 'ckanext.spatial.common_map.type':
        ensure  => absent,
        value   => '',
        require => Class['ckan::conf::production'],
      }
      ckan::conf::setting { 'ckanext.spatial.common_map.custom.url':
        ensure  => absent,
        value   => '',
        require => Class['ckan::conf::production'],
      }
      ckan::conf::setting { 'ckanext.spatial.common_map.attribution':
        ensure  => absent,
        value   => '',
        require => Class['ckan::conf::production'],
      }
    }
    'openstreetmap': {
      ckan::conf::setting { 'ckanext.spatial.common_map.type':
        value   => 'custom',
        require => Class['ckan::conf::production'],
      }
      ckan::conf::setting { 'ckanext.spatial.common_map.custom.url':
        value   => 'http://a.tile.openstreetmaps.org/{z}/{x}/{y}.png',
        require => Class['ckan::conf::production'],
      }
      ckan::conf::setting { 'ckanext.spatial.common_map.attribution':
        value   => "&copy <a href=\"http://www.openstreetmap.org/copyright\" target=\"_blank\">OpenStreetMap</a> contributors.\
  Tiles provided by <a href=\"https://maptiles.xyz\">MapTiles</a>.",
        require => Class['ckan::conf::production'],
      }
    }
    'mapquest': {
      #Nothing to do, this has been depricated.
    }
    'custom' : {
      ckan::conf::setting { 'ckanext.spatial.common_map.type':
        value   => 'custom',
        require => Class['ckan::conf::production'],
      }
      ckan::conf::setting { 'ckanext.spatial.common_map.custom.url':
        value   => $map_url,
        require => Class['ckan::conf::production'],
      }
      if $map_attribution {
        ckan::conf::setting { 'ckanext.spatial.common_map.attribution':
          value   => $map_attribution,
          require => Class['ckan::conf::production'],
        }
      }
    }
    default: {
      error('Unknown map_provider')
    }
  }
}