nostos-target-voyager 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -12,14 +12,23 @@ Add the following to your Gemfile and run `bundle install`
12
12
 
13
13
  ## Configuration
14
14
 
15
- In `config/application.rb` add the following options:
16
-
17
- config.target_voyager.host = ''
18
- config.target_voyager.port =
19
- config.target_voyager.username = ''
20
- config.target_voyager.password = ''
21
- config.target_voyager.operator = ''
22
- config.target_voyager.location = ''
15
+ You can interactively configure the Voyager target driver by running `rails generate target_voyager:install`. This will prompt you for the necessariy values.
16
+
17
+ You can manually configure the Voyager target driver in `config/target_voyager.rb`:
18
+
19
+ db:
20
+ adapter: 'oracle_enhanced'
21
+ database: # This is most likely VGER
22
+ username:
23
+ password:
24
+
25
+ sip:
26
+ host:
27
+ port:
28
+ username:
29
+ password:
30
+ operator:
31
+ location:
23
32
 
24
33
  Note that `username` and `location` is the operator id and location code used to sign into the SIP server (or Circulation module). `operator` is the operator id used for creating items. Theoretically they should be identical, however it is not required.
25
34
 
@@ -1,9 +1,8 @@
1
1
  require 'voyager'
2
- require 'nostos-target-voyager/railtie'
2
+ require 'nostos-target-voyager/railtie' if defined?(Rails)
3
3
  require 'nostos-target-voyager/config'
4
4
  require 'nostos-target-voyager/record'
5
-
6
- VoyagerGem = Voyager
5
+ require 'nostos-target-voyager/generators/target_voyager_generator' if defined?(Rails)
7
6
 
8
7
  module Target
9
8
  module Voyager
@@ -19,35 +18,30 @@ module Target
19
18
  def self.find(id)
20
19
  id = id.to_s unless id.is_a?(String)
21
20
 
22
- VoyagerGem::SIP::Client.new(config.sip[:host], config.sip[:port]) do |sip|
23
- sip.login(config.sip[:username], config.sip[:password], config.sip[:location]) do |response|
24
- if response[:ok] != '1' # Login failed
25
- Rails::logger.error "Failed to sign in to SIP server"
26
- return false
27
- end
28
-
29
- if response[:ok] == '1' # Login successful
30
- sip.item_status(id) do |item_status|
31
- return nil unless item_status[:AF] == 'Item Info retrieved successfully.'
21
+ item_barcode = ::Voyager::AR::Item::Barcode.includes(:item => [:circ_transaction, :bib_text]).where(:item_barcode => id).first
32
22
 
33
- if item_status[:circ_status] == '04' || item_status[:circ_status] == '05'
34
- target = Target::Voyager::Record.new(:id => id, :title => item_status[:AJ], :charged => true, :due_date => item_status[:AH])
35
- else
36
- target = Target::Voyager::Record.new(:id => id, :title => item_status[:AJ], :charged => false, :due_date => nil)
37
- end
38
-
39
- return target
40
- end
41
- end
42
- end
23
+ if item_barcode
24
+ Target::Voyager::Record.new(:id => item_barcode.item_barcode,
25
+ :title => item_barcode.item.bib_text.title,
26
+ :due_date => item_barcode.item.circ_transaction.try(:current_due_date),
27
+ :charged => !item_barcode.item.circ_transaction.nil?)
28
+ else
29
+ nil
43
30
  end
44
-
45
- nil
46
31
  end
47
32
 
48
33
  def self.create(item = {})
49
34
  return nil if item.id.nil? || item.title.nil?
50
35
 
36
+ # Check if the item already exists.
37
+ if ::Voyager::AR::Item::Barcode.where(:item_barcode => item.id.to_s).exists?
38
+ item_barcode = ::Voyager::AR::Item::Barcode.includes(:item => [:circ_transaction, :bib_text]).where(:item_barcode => item.id.to_s).first
39
+ return Target::Voyager::Record.new(:id => item_barcode.item_barcode,
40
+ :title => item_barcode.item.bib_text.title,
41
+ :due_date => item_barcode.item.circ_transaction.try(:current_due_date),
42
+ :charged => !item_barcode.item.circ_transaction.nil?)
43
+ end
44
+
51
45
  # Title should truncate to 32 characters and append "/ *12345*"
52
46
  title = "#{item.title[0..31]} / *#{item.id}*"
53
47
 
@@ -57,19 +51,20 @@ module Target
57
51
  end
58
52
  # Illiad encodes strings in Windows-1252, but Voyager SIP requires all messages be ASCII.
59
53
 
60
- VoyagerGem::SIP::Client.new(config.sip[:host], config.sip[:port]) do |sip|
61
- sip.login(config.sip[:username], config.sip[:password], config.sip[:location]) do |response|
54
+ ::Voyager::SIP::Client.new(config.sip["host"], config.sip["port"]) do |sip|
55
+ sip.login(config.sip["username"], config.sip["password"], config.sip["location"]) do |response|
62
56
  # First be sure that an item doesn't already exist.
63
57
  sip.item_status(item.id) do |item_status|
64
58
  unless item_status[:AF] == 'Item barcode not found. Please consult library personnel for assistance.'
65
59
  # Item already exists
60
+ # This should pretty much never happen since we check above for existence.
66
61
  return Target::Voyager::Record.new(:id => item.id,
67
62
  :title => item_status[:AJ],
68
63
  :due_date => item_status[:AH],
69
64
  :charged => !item_status[:AH].empty?)
70
65
  else
71
66
  # Item doesn't exist
72
- sip.create_bib(config.sip[:operator], title, item.id) do |response|
67
+ sip.create_bib(config.sip["operator"], title, item.id) do |response|
73
68
  # Bib/MFHD/Item created. Store values.
74
69
  #
75
70
  # Values must be stored in order to delete the items via SIP.
@@ -88,7 +83,7 @@ module Target
88
83
  end
89
84
 
90
85
  def self.charged
91
- VoyagerGem::AR::Item.joins(:circ_transaction).includes(:circ_transaction, :bib_text, :barcode).where(:item_type_id => 24).all.map do |item|
86
+ ::Voyager::AR::Item.joins(:circ_transaction).includes(:circ_transaction, :bib_text, :barcode).where(:item_type_id => 24).all.map do |item|
92
87
  Target::Voyager::Record.new(:id => item.barcode.item_barcode,
93
88
  :title => item.bib_item.bib_text.title,
94
89
  :due_date => item.circ_transaction.current_due_date,
@@ -0,0 +1,49 @@
1
+ require 'rails/generators'
2
+
3
+ module TargetVoyager
4
+ class InstallGenerator < Rails::Generators::Base
5
+ def configure
6
+ # Ask DB Questions
7
+ puts "Database Configuration:"
8
+ puts "The following fields are required to establish a connection with your Voyager server."
9
+ db = {}
10
+ db[:database] = ask('database: [VGER]')
11
+ db[:database] = 'VGER' if db[:database].blank?
12
+ db[:username] = ask('username (e.g. ro_XXXDB): []')
13
+ db[:password] = ask('password: []')
14
+
15
+ # Ask SIP Questions
16
+ puts "SIP Configuration:"
17
+ sip = {}
18
+ sip[:host] = ask('Host: []')
19
+ sip[:port] = ask('Port: [7031]')
20
+ sip[:port] = '7031' if sip[:port].blank?
21
+ sip[:username] = ask('Username (the operator used to sign into SIP. This will determine the allowed privleges and will be the operator used for circulation transactions): []')
22
+ sip[:password] = ask('Password: []')
23
+ sip[:operator] = ask('Operator (the operator used to create short records. This overrides the operator used to sign in. It is recommended that you create a cataloging operator for this driver so that you can easily identify records created in your ILS): []')
24
+ sip[:location] = ask('Location: []')
25
+
26
+ # Configure application settings
27
+ create_file File.join(Rails.root, 'config', 'target_voyager.yml'), <<CONFIG
28
+ # Target Voyager Configuration
29
+
30
+ # Database
31
+ db:
32
+ adapter: 'oracle_enhanced'
33
+ database: '#{db[:database]}'
34
+ username: '#{db[:username]}'
35
+ password: '#{db[:password]}'
36
+
37
+ # SIP
38
+ sip:
39
+ host: '#{sip[:host]}'
40
+ port: '#{sip[:port]}'
41
+ username: '#{sip[:username]}'
42
+ password: '#{sip[:password]}'
43
+ operator: '#{sip[:operator]}'
44
+ location: '#{sip[:location]}'
45
+ CONFIG
46
+
47
+ end
48
+ end
49
+ end
@@ -8,14 +8,18 @@ module Target
8
8
  config.target_voyager.db = ActiveSupport::OrderedOptions.new
9
9
 
10
10
  initializer "target_voyager.configure" do |app|
11
- Target::Voyager.configure do |config|
12
- config.sip = app.config.target_voyager[:sip]
13
- config.db = app.config.target_voyager[:db]
14
- end
15
- end
11
+ config_file = File.join(Rails.root, 'config', 'target_voyager.yml')
12
+
13
+ if File.exists?(config_file)
14
+ CONFIG = YAML::load(File.open(config_file))
16
15
 
17
- initializer "target_voyager.establish_connection", :after => "target_voyager.configure" do |app|
18
- VoyagerGem::AR::Base.establish_connection(Target::Voyager.config.db)
16
+ Target::Voyager.configure do |config|
17
+ config.sip = CONFIG["sip"]
18
+ config.db = CONFIG["db"]
19
+ end
20
+
21
+ ::Voyager::AR::Base.establish_connection(Target::Voyager.config.db)
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -1,5 +1,5 @@
1
1
  module Target
2
2
  module Voyager
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: nostos-target-voyager
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brice Stacey
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-15 00:00:00 Z
13
+ date: 2011-04-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: voyager
@@ -50,6 +50,7 @@ files:
50
50
  - Rakefile
51
51
  - lib/nostos-target-voyager.rb
52
52
  - lib/nostos-target-voyager/config.rb
53
+ - lib/nostos-target-voyager/generators/target_voyager_generator.rb
53
54
  - lib/nostos-target-voyager/railtie.rb
54
55
  - lib/nostos-target-voyager/record.rb
55
56
  - lib/nostos-target-voyager/version.rb