@@ -7,18 +7,6 @@ require 'find'
77require 'geo_combine/geo_blacklight_harvester'
88
99namespace :geocombine do
10- commit_within = ( ENV [ 'SOLR_COMMIT_WITHIN' ] || 5000 ) . to_i
11- ogm_path = ENV [ 'OGM_PATH' ] || 'tmp/opengeometadata'
12- solr_url = ENV [ 'SOLR_URL' ] || 'http://127.0.0.1:8983/solr/blacklight-core'
13- denylist = [
14- 'https://github.com/OpenGeoMetadata/GeoCombine.git' ,
15- 'https://github.com/OpenGeoMetadata/aardvark.git' ,
16- 'https://github.com/OpenGeoMetadata/metadata-issues.git' ,
17- 'https://github.com/OpenGeoMetadata/ogm_utils-python.git' ,
18- 'https://github.com/OpenGeoMetadata/opengeometadata.github.io.git' ,
19- 'https://github.com/OpenGeoMetadata/opengeometadata-rails.git'
20- ]
21-
2210 desc 'Clone OpenGeoMetadata repositories'
2311 task :clone , [ :repo ] do |_t , args |
2412 if args . repo
@@ -28,19 +16,19 @@ namespace :geocombine do
2816 ogm_repos = JSON . parse ( Net ::HTTP . get ( ogm_api_uri ) ) . map do |repo |
2917 repo [ 'clone_url' ] if ( repo [ 'size' ] ) . positive?
3018 end . compact
31- ogm_repos . reject! { |repo | denylist . include? ( repo ) }
19+ ogm_repos . reject! { |repo | GeoCombineRake . denylist . include? ( repo ) }
3220 end
3321 ogm_repos . each do |repo |
34- Kernel . system "echo #{ repo } && mkdir -p #{ ogm_path } && cd #{ ogm_path } && git clone --depth 1 #{ repo } "
22+ Kernel . system "echo #{ repo } && mkdir -p #{ GeoCombineRake . ogm_path } && cd #{ GeoCombineRake . ogm_path } && git clone --depth 1 #{ repo } "
3523 end
3624 end
3725
3826 desc '"git pull" OpenGeoMetadata repositories'
3927 task :pull , [ :repo ] do |_t , args |
4028 paths = if args . repo
41- [ File . join ( ogm_path , args . repo ) ]
29+ [ File . join ( GeoCombineRake . ogm_path , args . repo ) ]
4230 else
43- Dir . glob ( "#{ ogm_path } /*" )
31+ Dir . glob ( "#{ GeoCombineRake . ogm_path } /*" )
4432 end
4533 paths . each do |path |
4634 next unless File . directory? ( path )
@@ -51,15 +39,15 @@ namespace :geocombine do
5139
5240 desc 'Index all JSON documents except Layers.json'
5341 task :index do
54- puts "Indexing #{ ogm_path } into #{ solr_url } "
55- solr = RSolr . connect url : solr_url , adapter : :net_http_persistent
56- Find . find ( ogm_path ) do |path |
42+ puts "Indexing #{ GeoCombineRake . ogm_path } into #{ GeoCombineRake . solr_url } "
43+ solr = RSolr . connect url : GeoCombineRake . solr_url , adapter : :net_http_persistent
44+ Find . find ( GeoCombineRake . ogm_path ) do |path |
5745 next unless File . basename ( path ) . include? ( '.json' ) && File . basename ( path ) != 'layers.json'
5846
5947 doc = JSON . parse ( File . read ( path ) )
6048 [ doc ] . flatten . each do |record |
6149 puts "Indexing #{ record [ 'layer_slug_s' ] } : #{ path } " if $DEBUG
62- solr . update params : { commitWithin : commit_within , overwrite : true } ,
50+ solr . update params : { commitWithin : GeoCombineRake . commit_within , overwrite : true } ,
6351 data : [ record ] . to_json ,
6452 headers : { 'Content-Type' => 'application/json' }
6553 rescue RSolr ::Error ::Http => e
@@ -78,3 +66,29 @@ namespace :geocombine do
7866 end
7967 end
8068end
69+
70+ # Class to hold helper methods for use in GeoCombine rake tasks
71+ class GeoCombineRake
72+ def self . commit_within
73+ ( ENV [ 'SOLR_COMMIT_WITHIN' ] || 5000 ) . to_i
74+ end
75+
76+ def self . denylist
77+ [
78+ 'https://github.com/OpenGeoMetadata/GeoCombine.git' ,
79+ 'https://github.com/OpenGeoMetadata/aardvark.git' ,
80+ 'https://github.com/OpenGeoMetadata/metadata-issues.git' ,
81+ 'https://github.com/OpenGeoMetadata/ogm_utils-python.git' ,
82+ 'https://github.com/OpenGeoMetadata/opengeometadata.github.io.git' ,
83+ 'https://github.com/OpenGeoMetadata/opengeometadata-rails.git'
84+ ]
85+ end
86+
87+ def self . ogm_path
88+ ENV [ 'OGM_PATH' ] || 'tmp/opengeometadata'
89+ end
90+
91+ def self . solr_url
92+ ENV [ 'SOLR_URL' ] || 'http://127.0.0.1:8983/solr/blacklight-core'
93+ end
94+ end
0 commit comments