-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoid_component
54 lines (44 loc) · 1.58 KB
/
noid_component
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby
# frozen_string_literal: true
# Script displays a list of press monographs
require 'optparse'
require 'ostruct'
require 'os'
# Determine the root directory of the code base.
script_dir = File.expand_path(File.dirname(__FILE__))
root_dir = File.dirname(script_dir)
require_relative File.join(root_dir, "lib", "logger")
script_logger = UMPTG::Logger.create(logger_fp: STDOUT)
# Process the script parameters.
options = OpenStruct.new
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} noid [noid..]"
opts.on_tail('-h', '--help', 'Print this help message') do
script_logger.info(opts)
exit 0
end
end
option_parser.parse!(ARGV)
if ARGV.count < 1
script_logger.info(option_parser.help)
return
end
noid_list = ARGV
require_relative File.join(root_dir, 'lib', 'services')
# Create the serivce for retrieving the NOID.
service = UMPTG::Services::Heliotrope.new(
:fulcrum_host => options.fulcrum_host
)
products = service.products
c_list = products.collect {|c| c['identifier'] }
#script_logger.info("products:#{c_list.join(',')}")
noid_list.each do |noid|
response = service.connection.get("component", noid: noid).body
if response.nil?
script_logger.info("#{noid}:nil")
else
component = service.connection.get("components/#{response['id']}/products").body
c_list = component.collect {|c| c['identifier'] }
script_logger.info("#{noid},#{response['id']},=HYPERLINK(\"https://www.fulcrum.org/greensub/components/#{response['id']}\",\"#{response['id']}\"):#{c_list.join(',')}")
end
end