Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP-220: Add more option urls #8

Merged
merged 3 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/gingr-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ echo "publish vector to geoserver ends"

# import all with a zipfile
echo "4 - import all starting..."
ruby bin/gingr all spec/fixture/zipfile/test_public.zip
ruby bin/gingr all spec/fixture/zipfile/vector.zip --update-reference-field
echo "import all ends"
29 changes: 23 additions & 6 deletions lib/gingr/cli.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# frozen_string_literal: true

require 'thor'
require_relative 'import_util'
require_relative 'config'
require_relative 'watcher'

module Gingr
class Cli < Thor
include Config
include ImportUtil
include Logging

Expand Down Expand Up @@ -33,7 +36,7 @@ def watch(root_dir = nil)
long_desc <<-TEXT, wrapping: false
examples:\n
1) ruby bin/import solr tmp/test_public \n
2) ruby bin/import solr tmp/test_public --no-update_reference_field \n
2) ruby bin/import solr tmp/test_public --update-reference-field \n
(it will update reference urls from 'dct_references_s' field in each geoblacklight json file \n
with current spatial_url, geoserver_url, geoserver_secure_url)
TEXT
Expand All @@ -44,7 +47,7 @@ def watch(root_dir = nil)
option :solr_url
def solr(dir_path)
reference_urls = ImportUtil.get_reference_urls(options)
solr_url = options[:solr_url] || ENV.fetch('SOLR_URL', nil)
solr_url = options[:solr_url] || ENV.fetch('SOLR_URL', Config.default_options[:solr_url])
ImportUtil.index_solr_from_dir(dir_path, solr_url, reference_urls)
txt = "all json files under '#{dir_path}' and subdirectories have been indexed to solr #{solr_url} successfully"
logger.info(txt)
Expand All @@ -60,7 +63,13 @@ def solr(dir_path)
option :is_public, type: :boolean, default: true
def geoserver(filename)
url = options[:geoserver_url]
url ||= options[:is_public] ? ENV.fetch('GEOSERVER_URL', nil) : ENV.fetch('GEOSERVER_SECURE_URL', nil)
url ||= if options[:is_public]
ENV.fetch('GEOSERVER_URL', Config.default_options[:geoserver_url])
else
ENV.fetch(
'GEOSERVER_SECURE_URL', Config.default_options[:geoserver_secure_url]
)
end
publisher = GeoserverPublisher.new(url)
publisher.update(filename)
logger.info("'#{filename}' - published to geoserver #{url} successfully")
Expand All @@ -75,8 +84,10 @@ def geoserver(filename)
option :geoserver_root
def unpack(zipfile)
zipfile_path = zipfile == File.basename(zipfile) ? File.join(ImportUtil.root_path, 'import', zipfile) : zipfile
DataHandler.spatial_root = options[:spatial_root] || ENV.fetch('SPATIAL_ROOT', nil) || 'data/spatial/'
DataHandler.geoserver_root = options[:geoserver_root] || ENV.fetch('GEOSERVER_ROOT', nil) || 'data/geoserver/'
DataHandler.spatial_root = options[:spatial_root] || ENV.fetch('SPATIAL_ROOT',
Config.default_options[:spatial_root])
DataHandler.geoserver_root = options[:geoserver_root] || ENV.fetch('GEOSERVER_ROOT',
Config.default_options[:geoserver_root])

temp_path = File.join(Dir.pwd, 'tmp')
DataHandler.extract_and_move(zipfile_path, temp_path)
Expand Down Expand Up @@ -114,7 +125,13 @@ def all(zipfile)
option :is_public, type: :boolean, default: true
def geoserver_workspace(name)
url = options[:geoserver_url]
url ||= options[:is_public] ? ENV.fetch('GEOSERVER_URL', nil) : ENV.fetch('GEOSERVER_SECURE_URL', nil)
url ||= if options[:is_public]
ENV.fetch('GEOSERVER_URL', Config.default_options[:geoserver_url])
else
ENV.fetch(
'GEOSERVER_SECURE_URL', Config.default_options[:geoserver_secure_url]
)
end
publisher = GeoserverPublisher.new(url)
publisher.create_workspace(name)
logger.info("geoserver workspace '#{name}' - created successfully")
Expand Down
13 changes: 11 additions & 2 deletions lib/gingr/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ module Config
# dirname where all geofile related ingestion files located inside the ingestion zipfile
@geofile_ingestion_dirname = 'ingestion_files'

# default options for commands
@default_options = {
geoserver_secure_url: 'http://admin:geoserver@geoserver_secure:8080/geoserver/rest/',
geoserver_url: 'http://admin:geoserver@geoserver:8080/geoserver/rest/',
spatial_url: 'https://spatial.lib.berkeley.edu',
spatial_root: 'data/spatial/',
geoserver_root: 'data/geoserver/',
solr_url: 'http://solr:8983/solr/geodata-test'
}

class << self
attr_accessor :geofile_ingestion_dirname
attr_accessor :reference_urls
attr_accessor :geofile_ingestion_dirname, :reference_urls, :default_options

include Config
end
Expand Down
24 changes: 14 additions & 10 deletions lib/gingr/import_util.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'find'
require 'uri'
require_relative 'config'
Expand Down Expand Up @@ -50,7 +51,13 @@ def root_path
def publish_geoserver_files(files, url, is_public)
return if files.empty?

url ||= is_public ? ENV.fetch('GEOSERVER_URL', nil) : ENV.fetch('GEOSERVER_SECURE_URL', nil)
url ||= if is_public
ENV.fetch('GEOSERVER_URL',
Config.default_options[:geoserver_url])
else
ENV.fetch('GEOSERVER_SECURE_URL',
Config.default_options[:geoserver_secure_url])
end
publisher = GeoserverPublisher.new(url)
publisher.batch_update(files)
end
Expand All @@ -65,19 +72,16 @@ def geo_url(url)
def add_trailing_slash(url)
original_uri = URI.parse(url)
original_uri.path += '/' unless original_uri.path.end_with?('/')
original_uri.to_s
original_uri
end

def reference_url(key, options)
new_url = ''
if key == 'spatial_url'
new_url = options[key] || ENV.fetch(key.to_s.upcase, nil) || 'https://spatial.lib.berkeley.edu'
else
original_url = options[key] || ENV.fetch(key.to_s.upcase)
new_url = geo_url(original_url)
end
add_trailing_slash(new_url)
default_option_value = Config.default_options[key]
new_url = options[key] || ENV.fetch(key.to_s.upcase, default_option_value)
new_url = geo_url(new_url) if %w[geoserver_url geoserver_secure_url].include?(key.to_s)
add_trailing_slash(new_url).to_s
end

end
end
end