exlibris-aleph 0.0.1
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/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +38 -0
- data/lib/exlibris-aleph.rb +20 -0
- data/lib/exlibris/aleph/bor_auth.rb +40 -0
- data/lib/exlibris/aleph/config/config_base.rb +49 -0
- data/lib/exlibris/aleph/config/config_by_sub_library.rb +32 -0
- data/lib/exlibris/aleph/config/pc_tab_exp_field_extended.rb +20 -0
- data/lib/exlibris/aleph/config/tab15_by_item_process_status.rb +33 -0
- data/lib/exlibris/aleph/config/tab15_by_item_status.rb +33 -0
- data/lib/exlibris/aleph/config/tab31.rb +39 -0
- data/lib/exlibris/aleph/config/tab37.rb +50 -0
- data/lib/exlibris/aleph/config/tab40.rb +20 -0
- data/lib/exlibris/aleph/config/tab_sub_library.rb +21 -0
- data/lib/exlibris/aleph/config/tab_www_item_desc.rb +20 -0
- data/lib/exlibris/aleph/patron.rb +72 -0
- data/lib/exlibris/aleph/record.rb +56 -0
- data/lib/exlibris/aleph/rest.rb +31 -0
- data/lib/exlibris/aleph/tab_helper.rb +252 -0
- data/lib/exlibris/aleph/version.rb +5 -0
- data/lib/tasks/exlibris-aleph_tasks.rake +13 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/aleph/NYU50/collections.yml +1128 -0
- data/test/dummy/config/aleph/NYU50/item_permissions_by_item_process_status.yml +71226 -0
- data/test/dummy/config/aleph/NYU50/item_permissions_by_item_status.yml +20090 -0
- data/test/dummy/config/aleph/NYU50/items.yml +609 -0
- data/test/dummy/config/aleph/NYU50/patron_permissions.yml +22687 -0
- data/test/dummy/config/aleph/NYU50/patrons.yml +245 -0
- data/test/dummy/config/aleph/NYU50/pickup_locations.yml +2049 -0
- data/test/dummy/config/aleph/NYU51/collections.yml +41 -0
- data/test/dummy/config/aleph/NYU51/item_permissions_by_item_process_status.yml +7689 -0
- data/test/dummy/config/aleph/NYU51/item_permissions_by_item_status.yml +447 -0
- data/test/dummy/config/aleph/NYU51/items.yml +617 -0
- data/test/dummy/config/aleph/NYU51/patron_permissions.yml +6496 -0
- data/test/dummy/config/aleph/NYU51/patrons.yml +233 -0
- data/test/dummy/config/aleph/NYU51/pickup_locations.yml +456 -0
- data/test/dummy/config/aleph/sub_libraries.yml +756 -0
- data/test/dummy/config/application.rb +56 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/aleph.rb +1 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/aleph/aleph_tab_helper.log +1 -0
- data/test/dummy/log/test.log +1860 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/exlibris-aleph_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- data/test/unit/bor_auth_test.rb +24 -0
- data/test/unit/patron_test.rb +37 -0
- data/test/unit/record_benchmarks.rb +26 -0
- data/test/unit/record_test.rb +28 -0
- data/test/unit/tab_helper_benchmarks.rb +56 -0
- data/test/unit/tab_helper_test.rb +180 -0
- metadata +220 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
module Exlibris
|
2
|
+
module Aleph
|
3
|
+
class Patron < Rest
|
4
|
+
attr_accessor :patron_id
|
5
|
+
|
6
|
+
def initialize(patron_id, uri)
|
7
|
+
@patron_id = patron_id
|
8
|
+
raise "Initialization error in #{self.class}. Missing patron id." if @patron_id.nil?
|
9
|
+
super(uri)
|
10
|
+
@uri = @uri+ "/patron/#{patron_id}"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Place a hold on the specificed item.
|
14
|
+
# Raises errors if
|
15
|
+
def place_hold(adm_library, bib_library, bib_id, item_id, params)
|
16
|
+
pickup_location = params[:pickup_location]
|
17
|
+
raise "Error in place hold. Missing pickup location." if pickup_location.nil?
|
18
|
+
last_interest_date = params.fetch(:last_interest_date, "")
|
19
|
+
start_interest_date = params.fetch(:start_interest_date, "")
|
20
|
+
sub_author = params.fetch(:sub_author, "")
|
21
|
+
sub_title = params.fetch(:sub_title, "")
|
22
|
+
pages = params.fetch(:pages, "")
|
23
|
+
note_1 = params.fetch(:note_1, "")
|
24
|
+
note_2 = params.fetch(:note_2, "")
|
25
|
+
rush = params.fetch(:rush, "N")
|
26
|
+
body_str = "<hold-request-parameters>"
|
27
|
+
body_str << "<pickup-location>#{pickup_location}</pickup-location>"
|
28
|
+
body_str << "<last-interest-date>#{last_interest_date}</last-interest-date>"
|
29
|
+
body_str << "<start-interest-date>#{start_interest_date}</start-interest-date>"
|
30
|
+
body_str << "<sub-author>#{sub_author}</sub-author>"
|
31
|
+
body_str << "<sub-title>#{sub_title}</sub-title>"
|
32
|
+
body_str << "<pages>#{pages}</pages>"
|
33
|
+
body_str << "<note-1>#{note_1}</note-1>"
|
34
|
+
body_str << "<note-2>#{note_2}</note-2>"
|
35
|
+
body_str << "<rush>#{rush}</rush>"
|
36
|
+
body_str << "</hold-request-parameters>"
|
37
|
+
options = { :body => "post_xml=#{body_str}"}
|
38
|
+
@response = self.class.put(@uri+ "/record/#{bib_library}#{bib_id}/items/#{item_id}/hold", options)
|
39
|
+
raise "Error placing hold through Aleph REST APIs. #{error}" unless error.nil?
|
40
|
+
return @response
|
41
|
+
end
|
42
|
+
|
43
|
+
def get_address()
|
44
|
+
@response = self.class.get(self.uri+ "/patronInformation/address")
|
45
|
+
return nil unless error.nil?
|
46
|
+
return @response
|
47
|
+
end
|
48
|
+
|
49
|
+
def loans()
|
50
|
+
@response = self.class.get(@uri+ "/circulationActions/loans?view=full")
|
51
|
+
raise "Error getting loans through Aleph REST APIs. #{error}" unless error.nil?
|
52
|
+
return @response
|
53
|
+
end
|
54
|
+
|
55
|
+
def renew_loans(item_id="")
|
56
|
+
# Will renew all if specific item not specified
|
57
|
+
@response = self.class.post(@uri+ "/circulationActions/loans/#{item_id}")
|
58
|
+
raise "Error renewing loan(s) through Aleph REST APIs. #{error}" unless error.nil?
|
59
|
+
return @response
|
60
|
+
end
|
61
|
+
|
62
|
+
def note
|
63
|
+
return (not @response.first.last.kind_of?(Hash) or @response.first.last["create_hold"].nil?) ? "" : ": #{@response.first.last["create_hold"]["note"]}" if @response.instance_of?(Hash)
|
64
|
+
end
|
65
|
+
|
66
|
+
def error
|
67
|
+
return nil if reply_code == "0000"
|
68
|
+
return "#{reply_text}#{note}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Exlibris
|
2
|
+
module Aleph
|
3
|
+
class Record < Rest
|
4
|
+
def initialize(bib_library, record_id, uri)
|
5
|
+
@record_id = record_id
|
6
|
+
raise "Initialization error in #{self.class}. Missing record id." if @record_id.nil?
|
7
|
+
@bib_library = bib_library
|
8
|
+
raise "Initialization error in #{self.class}. Missing bib library." if @bib_library.nil?
|
9
|
+
super(uri)
|
10
|
+
@uri = @uri+ "/record/#{bib_library}#{record_id}"
|
11
|
+
# Format :xml parses response as a hash.
|
12
|
+
# Eventually I'd like this to be the default since it raises exceptions for invalid XML.
|
13
|
+
# self.class.format :xml
|
14
|
+
# Format :html does no parsing, just passes back raw XML for parsing by client
|
15
|
+
self.class.format :html
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns an XML string representation of a bib.
|
19
|
+
# Every method call refreshes the data from the underlying API.
|
20
|
+
# Raises and exception if there are errors.
|
21
|
+
def bib
|
22
|
+
@response = self.class.get(@uri+ "?view=full")
|
23
|
+
raise "Error getting bib from Aleph REST APIs. #{error}" unless error.nil?
|
24
|
+
return @response
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns an array of items. Each item is represented as an HTTParty hash.
|
28
|
+
# Every method call refreshes the data from the underlying API.
|
29
|
+
# Raises an exception if the response is not valid XML or there are errors.
|
30
|
+
def items
|
31
|
+
@items = []
|
32
|
+
self.class.format :xml
|
33
|
+
# Since we're parsing xml, this will raise an error
|
34
|
+
# if the response isn't xml.
|
35
|
+
@response = self.class.get(@uri+ "/items?view=full")
|
36
|
+
self.class.format :html
|
37
|
+
raise "Error getting items from Aleph REST APIs. #{error}" if not error.nil? or
|
38
|
+
@response.nil? or @response["get_item_list"].nil? or @response["get_item_list"]["items"].nil?
|
39
|
+
item_list = @response["get_item_list"]["items"]["item"]
|
40
|
+
@items.push(item_list) if item_list.instance_of?(Hash)
|
41
|
+
item_list.each {|item|@items.push(item)} if item_list.instance_of?(Array)
|
42
|
+
Rails.logger.warn("No items returned from Aleph in #{self.class}.") if @items.empty?
|
43
|
+
return @items
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns an XML string representation of holdings
|
47
|
+
# Every method call refreshes the data from the underlying API.
|
48
|
+
# Raises and exception if there are errors.
|
49
|
+
def holdings
|
50
|
+
@response = self.class.get(@uri+ "/holdings?view=full")
|
51
|
+
raise "Error getting holdings from Aleph REST APIs. #{error}" unless error.nil?
|
52
|
+
return @response
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Exlibris
|
2
|
+
module Aleph
|
3
|
+
require 'httparty'
|
4
|
+
class Rest
|
5
|
+
include HTTParty
|
6
|
+
format :xml
|
7
|
+
def initialize(uri)
|
8
|
+
@uri = uri
|
9
|
+
raise "Initialization error in #{self.class}. Missing URI." if @uri.nil?
|
10
|
+
end
|
11
|
+
def error
|
12
|
+
return nil if reply_code == "0000"
|
13
|
+
return "#{reply_text}"
|
14
|
+
end
|
15
|
+
def reply_code
|
16
|
+
return "No response." if @response.nil?
|
17
|
+
return (not @response.first.last.kind_of?(Hash) or @response.first.last["reply_code"].nil?) ? "Unexpected response hash." : @response.first.last["reply_code"] if @response.instance_of?(Hash)
|
18
|
+
response_match = @response.match(/\<reply-code\>(.+)\<\/reply-code\>/) if @response.instance_of?(String)
|
19
|
+
return (response_match.nil?) ? "Unexpected response string." : response_match[1] if @response.instance_of?(String)
|
20
|
+
return "Unexpected response type."
|
21
|
+
end
|
22
|
+
def reply_text
|
23
|
+
return "No response." if @response.nil?
|
24
|
+
return (not @response.first.last.kind_of?(Hash) or @response.first.last["reply_text"].nil?) ? "Unexpected response hash." : @response.first.last["reply_text"] if @response.instance_of?(Hash)
|
25
|
+
response_match = @response.match(/\<reply-text\>(.+)\<\/reply-text\>/) if @response.instance_of?(String)
|
26
|
+
return (response_match.nil?) ? "Unexpected response string." : response_match[1] if @response.instance_of?(String)
|
27
|
+
return "Unexpected response type."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
# This guy is a singleton, get one with Exlibris::Aleph::TabHelper.instance
|
2
|
+
module Exlibris
|
3
|
+
module Aleph
|
4
|
+
require 'singleton'
|
5
|
+
require 'yaml'
|
6
|
+
class TabHelper
|
7
|
+
include Singleton
|
8
|
+
attr_reader :sub_libraries, :updated_at
|
9
|
+
@@tabs = {
|
10
|
+
:patrons => :PcTabExpFieldExtended,
|
11
|
+
:patron_permissions => :Tab31,
|
12
|
+
:items => :TabWwwItemDesc,
|
13
|
+
:item_permissions_by_item_status => :Tab15ByItemStatus,
|
14
|
+
:item_permissions_by_item_process_status => :Tab15ByItemProcessStatus,
|
15
|
+
:collections => :Tab40,
|
16
|
+
:pickup_locations => :Tab37}
|
17
|
+
@@adms = []
|
18
|
+
@@tab_path = nil
|
19
|
+
@@yml_path = nil
|
20
|
+
@@log_path = nil
|
21
|
+
|
22
|
+
def self.init(tab_path, yml_path, log_path, adms)
|
23
|
+
@@tab_path = tab_path
|
24
|
+
@@adms = adms
|
25
|
+
@@yml_path = yml_path
|
26
|
+
@@log_path = log_path
|
27
|
+
Dir.mkdir(yml_path) unless Dir.exist?(yml_path)
|
28
|
+
@@adms.each { |adm| Dir.mkdir(File.join(yml_path, adm)) unless Dir.exist?(File.join(yml_path, adm)) }
|
29
|
+
Dir.mkdir(log_path) unless Dir.exist?(log_path)
|
30
|
+
# Make readers for each class variable
|
31
|
+
class_variables.each do |class_variable|
|
32
|
+
define_method "#{class_variable}".sub('@@', '') do
|
33
|
+
self.class.class_variable_get "#{class_variable}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.refresh_yml
|
39
|
+
tab = Exlibris::Aleph::Config::TabSubLibrary.new({
|
40
|
+
:aleph_library => "ALEPHE", :aleph_mnt_path => @@tab_path}).to_h
|
41
|
+
File.open(File.join(@@yml_path, "#{:sub_libraries}.yml"), 'w') { |out| YAML.dump( tab, out ) } unless tab.empty?
|
42
|
+
@@tabs.each do |tab_name, tab_class|
|
43
|
+
@@adms.each do |adm|
|
44
|
+
tab = Exlibris::Aleph::Config.const_get(tab_class).new({
|
45
|
+
:aleph_library => adm, :aleph_mnt_path => @@tab_path}).to_h
|
46
|
+
File.open( File.join(@@yml_path, adm, "#{tab_name}.yml"), 'w' ) { |out| YAML.dump( tab, out ) } unless tab.empty?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def initialize
|
52
|
+
raise ArgumentError.new("No tab path was specified.") if @@tab_path.nil?
|
53
|
+
raise ArgumentError.new("No yml path was specified.") if @@yml_path.nil?
|
54
|
+
raise ArgumentError.new("No log path was specified.") if @@log_path.nil?
|
55
|
+
raise ArgumentError.new("No ADMs were specified.") if @@adms.empty?
|
56
|
+
self.class.refresh_yml
|
57
|
+
@helper_log = Logger.new(File.join(@@log_path, "tab_helper.log"))
|
58
|
+
@helper_log.level = Logger::WARN
|
59
|
+
@patrons = {}
|
60
|
+
@patron_permissions = {}
|
61
|
+
@items = {}
|
62
|
+
@item_permissions_by_item_status = {}
|
63
|
+
@item_permissions_by_item_process_status = {}
|
64
|
+
@collections = {}
|
65
|
+
@pickup_locations = {}
|
66
|
+
@sub_libraries = {}
|
67
|
+
@@tabs.each_key { |tab| self.class.send(:attr_reader, tab) }
|
68
|
+
refresh
|
69
|
+
end
|
70
|
+
|
71
|
+
def sub_library_text(params)
|
72
|
+
# raise_required_parameter_error :sub_library_code if params[:sub_library_code].nil?
|
73
|
+
sub_library = @sub_libraries[params[:sub_library_code]]
|
74
|
+
return sub_library[:text] unless sub_library.nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
def sub_library_adm(params)
|
78
|
+
# raise_required_parameter_error :sub_library_code if params[:sub_library_code].nil?
|
79
|
+
sub_library = @sub_libraries[params[:sub_library_code]]
|
80
|
+
return sub_library[:library] unless sub_library.nil?
|
81
|
+
end
|
82
|
+
|
83
|
+
def item_pickup_locations(params)
|
84
|
+
# raise_required_parameter_error :adm_library_code if params[:adm_library_code].nil?
|
85
|
+
# raise_required_parameter_error :sub_library_code if params[:sub_library_code].nil?
|
86
|
+
# raise_required_parameter_error :item_status_code if params[:item_status_code].nil?
|
87
|
+
# raise_required_parameter_error :item_process_status_code if params[:item_process_status_code].nil?
|
88
|
+
# raise_required_parameter_error :bor_status if params[:bor_status].nil?
|
89
|
+
# raise_required_parameter_error :availability_status if params[:availability_status].nil?
|
90
|
+
adm_locations = pickup_locations[params[:adm_library_code]]
|
91
|
+
sub_locations = adm_locations[params[:sub_library_code]] unless adm_locations.nil?
|
92
|
+
|
93
|
+
# First try the most specific
|
94
|
+
item_locations = sub_locations[params[:item_status_code]] unless sub_locations.nil?
|
95
|
+
item_procesing_locations = item_locations[params[:item_process_status_code]] unless item_locations.nil?
|
96
|
+
borrower_locations = item_procesing_locations[params[:bor_status]] unless item_procesing_locations.nil?
|
97
|
+
availability_locations = item_procesing_locations[params[:bor_status]] unless item_procesing_locations.nil?
|
98
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
99
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
100
|
+
return locations[:pickup_locations] unless locations.nil?
|
101
|
+
|
102
|
+
# Wild card item status
|
103
|
+
item_locations, item_procesing_locations, borrower_locations = nil, nil, nil
|
104
|
+
item_locations = sub_locations["##"] unless sub_locations.nil?
|
105
|
+
item_procesing_locations = item_locations[params[:item_process_status_code]] unless item_locations.nil?
|
106
|
+
borrower_locations = item_procesing_locations[params[:bor_status]] unless item_procesing_locations.nil?
|
107
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
108
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
109
|
+
return locations[:pickup_locations] unless locations.nil?
|
110
|
+
|
111
|
+
# Wild card item process status
|
112
|
+
item_locations, item_procesing_locations, borrower_locations = nil, nil, nil
|
113
|
+
item_locations = sub_locations[params[:item_status_code]] unless sub_locations.nil?
|
114
|
+
item_procesing_locations = item_locations["##"] unless item_locations.nil?
|
115
|
+
borrower_locations = item_procesing_locations[params[:bor_status]] unless item_procesing_locations.nil?
|
116
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
117
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
118
|
+
return locations[:pickup_locations] unless locations.nil?
|
119
|
+
|
120
|
+
# Wild card item status and item process status
|
121
|
+
item_locations, item_procesing_locations, borrower_locations = nil, nil, nil
|
122
|
+
item_locations = sub_locations["##"] unless sub_locations.nil?
|
123
|
+
item_procesing_locations = item_locations["##"] unless item_locations.nil?
|
124
|
+
borrower_locations = item_procesing_locations[params[:bor_status]] unless item_procesing_locations.nil?
|
125
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
126
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
127
|
+
return locations[:pickup_locations] unless locations.nil?
|
128
|
+
|
129
|
+
# Wild card patron status
|
130
|
+
item_locations, item_procesing_locations, borrower_locations = nil, nil, nil
|
131
|
+
item_locations = sub_locations[params[:item_status_code]] unless sub_locations.nil?
|
132
|
+
item_procesing_locations = item_locations[params[:item_process_status_code]] unless item_locations.nil?
|
133
|
+
borrower_locations = item_procesing_locations["##"] unless item_procesing_locations.nil?
|
134
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
135
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
136
|
+
return locations[:pickup_locations] unless locations.nil?
|
137
|
+
|
138
|
+
# Wild card patron status and item status
|
139
|
+
item_locations, item_procesing_locations, borrower_locations = nil, nil, nil
|
140
|
+
item_locations = sub_locations["##"] unless sub_locations.nil?
|
141
|
+
item_procesing_locations = item_locations[params[:item_process_status_code]] unless item_locations.nil?
|
142
|
+
borrower_locations = item_procesing_locations["##"] unless item_procesing_locations.nil?
|
143
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
144
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
145
|
+
return locations[:pickup_locations] unless locations.nil?
|
146
|
+
|
147
|
+
# Wild card patron status and item process status
|
148
|
+
item_locations, item_procesing_locations, borrower_locations = nil, nil, nil
|
149
|
+
item_locations = sub_locations[params[:item_status_code]] unless sub_locations.nil?
|
150
|
+
item_procesing_locations = item_locations["##"] unless item_locations.nil?
|
151
|
+
borrower_locations = item_procesing_locations["##"] unless item_procesing_locations.nil?
|
152
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
153
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
154
|
+
return locations[:pickup_locations] unless locations.nil?
|
155
|
+
|
156
|
+
# Wild card everything
|
157
|
+
item_locations, item_procesing_locations, borrower_locations = nil, nil, nil
|
158
|
+
item_locations = sub_locations["##"] unless sub_locations.nil?
|
159
|
+
item_procesing_locations = item_locations["##"] unless item_locations.nil?
|
160
|
+
borrower_locations = item_procesing_locations["##"] unless item_procesing_locations.nil?
|
161
|
+
locations = (borrower_locations.has_key?(params[:availability_status])) ?
|
162
|
+
borrower_locations[:availability_status] : borrower_locations["#"] unless borrower_locations.nil?
|
163
|
+
return locations[:pickup_locations] unless locations.nil?
|
164
|
+
|
165
|
+
# Set the pickup location to default to the passed in sub library
|
166
|
+
@helper_log.warn(
|
167
|
+
"Warning in #{self.class}. "+
|
168
|
+
"Pickup locations not found. "+
|
169
|
+
"Defaulting to Aleph item sub library, #{params[:sub_library_code]}.\n"+
|
170
|
+
"Additional parameters:\n"+
|
171
|
+
"\tADM library: #{params[:adm_library_code]}\n"+
|
172
|
+
"\tSub library: #{params[:sub_library_code]}\n"+
|
173
|
+
"\tItem status: #{params[:item_status_code]}\n"+
|
174
|
+
"\tItem process status: #{params[:item_process_status_code]}\n"+
|
175
|
+
"\tAvailability status: #{params[:availability_status]}\n"+
|
176
|
+
"\tBorrower status: #{params[:bor_status]}\n"
|
177
|
+
)
|
178
|
+
return [params[:sub_library_code]]
|
179
|
+
end
|
180
|
+
|
181
|
+
def collection_text(params)
|
182
|
+
# raise_required_parameter_error :adm_library_code if params[:adm_library_code].nil?
|
183
|
+
# raise_required_parameter_error :sub_library_code if params[:sub_library_code].nil?
|
184
|
+
# raise_required_parameter_error :collection_code if params[:collection_code].nil?
|
185
|
+
adm = collections[params[:adm_library_code]]
|
186
|
+
sub = adm[params[:sub_library_code]] unless adm.nil?
|
187
|
+
coll = sub[params[:collection_code]] unless sub.nil?
|
188
|
+
return coll[:text] unless coll.nil?
|
189
|
+
end
|
190
|
+
|
191
|
+
def item_web_text(params)
|
192
|
+
adm = items[params[:adm_library_code]]
|
193
|
+
item = (adm[params[:item_process_status]].nil?) ? adm[params[:item_status]] : adm[params[:item_process_status]] unless (params[:item_status].nil? and params[:item_process_status]) or adm.nil?
|
194
|
+
permissions = item_permissions(params) if item.nil?
|
195
|
+
item = adm[permissions[:text]] unless permissions.nil? or adm.nil?
|
196
|
+
return item[:web_text] unless item.nil?
|
197
|
+
return permissions[:text] unless permissions.nil?
|
198
|
+
end
|
199
|
+
|
200
|
+
def item_permissions(params)
|
201
|
+
unless params[:item_process_status_code].nil?
|
202
|
+
adm_permissions =
|
203
|
+
item_permissions_by_item_process_status[params[:adm_library_code]]
|
204
|
+
sublibrary_permissions =
|
205
|
+
adm_permissions[params[:sub_library_code]] unless adm_permissions.nil?
|
206
|
+
item_process_status_permissions =
|
207
|
+
sublibrary_permissions[params[:item_process_status_code]] unless sublibrary_permissions.nil?
|
208
|
+
return item_process_status_permissions unless item_process_status_permissions.nil?
|
209
|
+
end
|
210
|
+
unless params[:item_status_code].nil?
|
211
|
+
adm_permissions = item_permissions_by_item_status[params[:adm_library_code]]
|
212
|
+
sublibrary_permissions =
|
213
|
+
adm_permissions[params[:sub_library_code]] unless adm_permissions.nil?
|
214
|
+
item_status_permissions =
|
215
|
+
sublibrary_permissions[params[:item_status_code]] unless sublibrary_permissions.nil?
|
216
|
+
return item_status_permissions unless item_status_permissions.nil?
|
217
|
+
end
|
218
|
+
@helper_log.warn(
|
219
|
+
"Warning in #{self.class}. "+
|
220
|
+
"Item permissions not found. "+
|
221
|
+
"Additional parameters:\n"+
|
222
|
+
"\tADM library: #{params[:adm_library_code]}\n"+
|
223
|
+
"\tSub library: #{params[:sub_library_code]}\n"+
|
224
|
+
"\tItem status: #{params[:item_status_code]}\n"+
|
225
|
+
"\tItem process status: #{params[:item_process_status_code]}"
|
226
|
+
)
|
227
|
+
return {}
|
228
|
+
end
|
229
|
+
|
230
|
+
def refresh?
|
231
|
+
return true if (@updated_at.nil? or @updated_at < 1.day.ago)
|
232
|
+
end
|
233
|
+
|
234
|
+
def refresh
|
235
|
+
@updated_at = Time.now()
|
236
|
+
@sub_libraries = YAML.load_file(File.join(@@yml_path, "#{:sub_libraries}.yml"))
|
237
|
+
@@tabs.each_key do |tab_name|
|
238
|
+
@@adms.each do |adm|
|
239
|
+
tab = instance_variable_get("@#{tab_name}".to_sym)
|
240
|
+
tab[adm] = YAML.load_file(File.join(@@yml_path, adm, "#{tab_name}.yml"))
|
241
|
+
instance_variable_set("@#{tab_name}".to_sym, tab)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
private
|
247
|
+
def raise_required_parameter_error(parameter)
|
248
|
+
raise "Initialization error in #{self.class}. Missing required parameter: #{parameter}."
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# desc "Explaining what the task does"
|
2
|
+
# task :exlibris:aleph do
|
3
|
+
# # Task goes here
|
4
|
+
# end
|
5
|
+
namespace :exlibris do
|
6
|
+
namespace :aleph do
|
7
|
+
|
8
|
+
desc "Refresh Aleph YAML Config"
|
9
|
+
task :refresh, [:aleph_mnt_path] => :environment do |t, args|
|
10
|
+
Exlibris::Aleph::TabHelper.refresh_yml
|
11
|
+
end
|
12
|
+
end
|
13
|
+
emd
|
@@ -0,0 +1,261 @@
|
|
1
|
+
== Welcome to Rails
|
2
|
+
|
3
|
+
Rails is a web-application framework that includes everything needed to create
|
4
|
+
database-backed web applications according to the Model-View-Control pattern.
|
5
|
+
|
6
|
+
This pattern splits the view (also called the presentation) into "dumb"
|
7
|
+
templates that are primarily responsible for inserting pre-built data in between
|
8
|
+
HTML tags. The model contains the "smart" domain objects (such as Account,
|
9
|
+
Product, Person, Post) that holds all the business logic and knows how to
|
10
|
+
persist themselves to a database. The controller handles the incoming requests
|
11
|
+
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
12
|
+
and directing data to the view.
|
13
|
+
|
14
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
15
|
+
layer entitled Active Record. This layer allows you to present the data from
|
16
|
+
database rows as objects and embellish these data objects with business logic
|
17
|
+
methods. You can read more about Active Record in
|
18
|
+
link:files/vendor/rails/activerecord/README.html.
|
19
|
+
|
20
|
+
The controller and view are handled by the Action Pack, which handles both
|
21
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
22
|
+
are bundled in a single package due to their heavy interdependence. This is
|
23
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
24
|
+
more separate. Each of these packages can be used independently outside of
|
25
|
+
Rails. You can read more about Action Pack in
|
26
|
+
link:files/vendor/rails/actionpack/README.html.
|
27
|
+
|
28
|
+
|
29
|
+
== Getting Started
|
30
|
+
|
31
|
+
1. At the command prompt, create a new Rails application:
|
32
|
+
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
33
|
+
|
34
|
+
2. Change directory to <tt>myapp</tt> and start the web server:
|
35
|
+
<tt>cd myapp; rails server</tt> (run with --help for options)
|
36
|
+
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
39
|
+
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
42
|
+
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
45
|
+
|
46
|
+
|
47
|
+
== Debugging Rails
|
48
|
+
|
49
|
+
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
50
|
+
will help you debug it and get it back on the rails.
|
51
|
+
|
52
|
+
First area to check is the application log files. Have "tail -f" commands
|
53
|
+
running on the server.log and development.log. Rails will automatically display
|
54
|
+
debugging and runtime information to these files. Debugging info will also be
|
55
|
+
shown in the browser on requests from 127.0.0.1.
|
56
|
+
|
57
|
+
You can also log your own messages directly into the log file from your code
|
58
|
+
using the Ruby logger class from inside your controllers. Example:
|
59
|
+
|
60
|
+
class WeblogController < ActionController::Base
|
61
|
+
def destroy
|
62
|
+
@weblog = Weblog.find(params[:id])
|
63
|
+
@weblog.destroy
|
64
|
+
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
The result will be a message in your log file along the lines of:
|
69
|
+
|
70
|
+
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
71
|
+
|
72
|
+
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
73
|
+
|
74
|
+
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
75
|
+
several books available online as well:
|
76
|
+
|
77
|
+
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
78
|
+
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
79
|
+
|
80
|
+
These two books will bring you up to speed on the Ruby language and also on
|
81
|
+
programming in general.
|
82
|
+
|
83
|
+
|
84
|
+
== Debugger
|
85
|
+
|
86
|
+
Debugger support is available through the debugger command when you start your
|
87
|
+
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
88
|
+
execution at any point in the code, investigate and change the model, and then,
|
89
|
+
resume execution! You need to install ruby-debug to run the server in debugging
|
90
|
+
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
91
|
+
|
92
|
+
class WeblogController < ActionController::Base
|
93
|
+
def index
|
94
|
+
@posts = Post.all
|
95
|
+
debugger
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
So the controller will accept the action, run the first line, then present you
|
100
|
+
with a IRB prompt in the server window. Here you can do things like:
|
101
|
+
|
102
|
+
>> @posts.inspect
|
103
|
+
=> "[#<Post:0x14a6be8
|
104
|
+
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
105
|
+
#<Post:0x14a6620
|
106
|
+
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
107
|
+
>> @posts.first.title = "hello from a debugger"
|
108
|
+
=> "hello from a debugger"
|
109
|
+
|
110
|
+
...and even better, you can examine how your runtime objects actually work:
|
111
|
+
|
112
|
+
>> f = @posts.first
|
113
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
114
|
+
>> f.
|
115
|
+
Display all 152 possibilities? (y or n)
|
116
|
+
|
117
|
+
Finally, when you're ready to resume execution, you can enter "cont".
|
118
|
+
|
119
|
+
|
120
|
+
== Console
|
121
|
+
|
122
|
+
The console is a Ruby shell, which allows you to interact with your
|
123
|
+
application's domain model. Here you'll have all parts of the application
|
124
|
+
configured, just like it is when the application is running. You can inspect
|
125
|
+
domain models, change values, and save to the database. Starting the script
|
126
|
+
without arguments will launch it in the development environment.
|
127
|
+
|
128
|
+
To start the console, run <tt>rails console</tt> from the application
|
129
|
+
directory.
|
130
|
+
|
131
|
+
Options:
|
132
|
+
|
133
|
+
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
134
|
+
made to the database.
|
135
|
+
* Passing an environment name as an argument will load the corresponding
|
136
|
+
environment. Example: <tt>rails console production</tt>.
|
137
|
+
|
138
|
+
To reload your controllers and models after launching the console run
|
139
|
+
<tt>reload!</tt>
|
140
|
+
|
141
|
+
More information about irb can be found at:
|
142
|
+
link:http://www.rubycentral.org/pickaxe/irb.html
|
143
|
+
|
144
|
+
|
145
|
+
== dbconsole
|
146
|
+
|
147
|
+
You can go to the command line of your database directly through <tt>rails
|
148
|
+
dbconsole</tt>. You would be connected to the database with the credentials
|
149
|
+
defined in database.yml. Starting the script without arguments will connect you
|
150
|
+
to the development database. Passing an argument will connect you to a different
|
151
|
+
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
152
|
+
PostgreSQL and SQLite 3.
|
153
|
+
|
154
|
+
== Description of Contents
|
155
|
+
|
156
|
+
The default directory structure of a generated Ruby on Rails application:
|
157
|
+
|
158
|
+
|-- app
|
159
|
+
| |-- assets
|
160
|
+
| |-- images
|
161
|
+
| |-- javascripts
|
162
|
+
| `-- stylesheets
|
163
|
+
| |-- controllers
|
164
|
+
| |-- helpers
|
165
|
+
| |-- mailers
|
166
|
+
| |-- models
|
167
|
+
| `-- views
|
168
|
+
| `-- layouts
|
169
|
+
|-- config
|
170
|
+
| |-- environments
|
171
|
+
| |-- initializers
|
172
|
+
| `-- locales
|
173
|
+
|-- db
|
174
|
+
|-- doc
|
175
|
+
|-- lib
|
176
|
+
| `-- tasks
|
177
|
+
|-- log
|
178
|
+
|-- public
|
179
|
+
|-- script
|
180
|
+
|-- test
|
181
|
+
| |-- fixtures
|
182
|
+
| |-- functional
|
183
|
+
| |-- integration
|
184
|
+
| |-- performance
|
185
|
+
| `-- unit
|
186
|
+
|-- tmp
|
187
|
+
| |-- cache
|
188
|
+
| |-- pids
|
189
|
+
| |-- sessions
|
190
|
+
| `-- sockets
|
191
|
+
`-- vendor
|
192
|
+
|-- assets
|
193
|
+
`-- stylesheets
|
194
|
+
`-- plugins
|
195
|
+
|
196
|
+
app
|
197
|
+
Holds all the code that's specific to this particular application.
|
198
|
+
|
199
|
+
app/assets
|
200
|
+
Contains subdirectories for images, stylesheets, and JavaScript files.
|
201
|
+
|
202
|
+
app/controllers
|
203
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
204
|
+
automated URL mapping. All controllers should descend from
|
205
|
+
ApplicationController which itself descends from ActionController::Base.
|
206
|
+
|
207
|
+
app/models
|
208
|
+
Holds models that should be named like post.rb. Models descend from
|
209
|
+
ActiveRecord::Base by default.
|
210
|
+
|
211
|
+
app/views
|
212
|
+
Holds the template files for the view that should be named like
|
213
|
+
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
214
|
+
eRuby syntax by default.
|
215
|
+
|
216
|
+
app/views/layouts
|
217
|
+
Holds the template files for layouts to be used with views. This models the
|
218
|
+
common header/footer method of wrapping views. In your views, define a layout
|
219
|
+
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
220
|
+
Inside default.html.erb, call <% yield %> to render the view using this
|
221
|
+
layout.
|
222
|
+
|
223
|
+
app/helpers
|
224
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are
|
225
|
+
generated for you automatically when using generators for controllers.
|
226
|
+
Helpers can be used to wrap functionality for your views into methods.
|
227
|
+
|
228
|
+
config
|
229
|
+
Configuration files for the Rails environment, the routing map, the database,
|
230
|
+
and other dependencies.
|
231
|
+
|
232
|
+
db
|
233
|
+
Contains the database schema in schema.rb. db/migrate contains all the
|
234
|
+
sequence of Migrations for your schema.
|
235
|
+
|
236
|
+
doc
|
237
|
+
This directory is where your application documentation will be stored when
|
238
|
+
generated using <tt>rake doc:app</tt>
|
239
|
+
|
240
|
+
lib
|
241
|
+
Application specific libraries. Basically, any kind of custom code that
|
242
|
+
doesn't belong under controllers, models, or helpers. This directory is in
|
243
|
+
the load path.
|
244
|
+
|
245
|
+
public
|
246
|
+
The directory available for the web server. Also contains the dispatchers and the
|
247
|
+
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
248
|
+
server.
|
249
|
+
|
250
|
+
script
|
251
|
+
Helper scripts for automation and generation.
|
252
|
+
|
253
|
+
test
|
254
|
+
Unit and functional tests along with fixtures. When using the rails generate
|
255
|
+
command, template test files will be generated for you and placed in this
|
256
|
+
directory.
|
257
|
+
|
258
|
+
vendor
|
259
|
+
External libraries that the application depends on. Also includes the plugins
|
260
|
+
subdirectory. If the app has frozen rails, those gems also go here, under
|
261
|
+
vendor/rails/. This directory is in the load path.
|