traject_horizon 0.11.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f8ac4a546bb69032c0da921fa9a749ef83a6d96
4
+ data.tar.gz: 530cc90de2a1eb2ffb52eda7601bbc5076be3bf7
5
+ SHA512:
6
+ metadata.gz: d5e490f9706b94fa747b21c689255320b9cd96dfe6cd1b93c63d32952496e293a90f550d5a8449d87d4a05c39a8a59cd049399e004bd75f031a9a55048ffb718
7
+ data.tar.gz: a766c0d3a2418017d0dcfe562737b4b647bb28e8e9d05dad9fc55be617e6de69c53dcbdd415bb153e4e56de1ea8bdd3cb0599728ef5dc729f16c23049a00764b
data/README.md CHANGED
@@ -54,6 +54,9 @@ settings do
54
54
  # or "sqlserver:", including username on the end but not password:
55
55
  provide "horizon.jdbc_url", "jdbc:jtds:sybase://horizonserver.university.edu:2025/horizon_db;user=esys"
56
56
 
57
+ # Instead of horizon.jdbc_url, you can also use individual
58
+ # horizon.host, horizon.port, horizon.database, horizon.user
59
+
57
60
  # DB password in seperate setting
58
61
  provide "horizon.jdbc_password", "drilg53"
59
62
 
@@ -18,7 +18,17 @@ module Traject
18
18
  # it from logging. Eg: "jdbc:jtds:sybase://horizon.lib.univ.edu:2025/dbname;user=dbuser"
19
19
  # * In command line, you'll have to use quotes: -s 'horizon.jdbc_url=jdbc:jtds:sybase://horizon.lib.univ.edu:2025/dbname;user=dbuser'
20
20
  #
21
- # [horizon.jdbc_password] Password to use for JDBC connection. We'll try to suppress it from being logged.
21
+ #
22
+ # [horizon.password] Password to use for JDBC connection. We'll try to suppress it from being logged.
23
+ #
24
+ # Instead of jdbc_url, you can provide all the other elements individually:
25
+ #
26
+ # [horizon.host]
27
+ # [horizon.port] (default 2025)
28
+ # [horizon.user]
29
+ # [horizon.database] (default 'horizon')
30
+ # [horizon.jtds_type] default 'sybase', or 'sqlserver'
31
+ #
22
32
  #
23
33
  # == What to export
24
34
  #
@@ -129,7 +139,7 @@ module Traject
129
139
 
130
140
  require_jars!
131
141
 
132
- logger.info(" #{self.class.name} reading records from #{settings["horizon.jdbc_url"]}")
142
+ logger.info(" #{self.class.name} reading records from #{jdbc_url(false)}")
133
143
  end
134
144
 
135
145
  # Requires marc4j and jtds, and java_import's some classes.
@@ -244,8 +254,8 @@ module Traject
244
254
 
245
255
  # Turn Horizon's weird escaping into UTF8: <U+nnnn> where nnnn is a hex unicode
246
256
  # codepoint, turn it UTF8 for that codepoint
247
- if false && settings["horizon.codepoint_translate"].to_s == "true" && settings["horizon.destination_encoding"] == "UTF8"
248
- text.gsub!(/\<U\+([0-9A-F]{4})\>/) do
257
+ if settings["horizon.codepoint_translate"].to_s == "true" && settings["horizon.destination_encoding"] == "UTF8"
258
+ text.gsub!(/\<U\+([0-9A-Fa-f]{4})\>/) do
249
259
  [$1.hex].pack("U")
250
260
  end
251
261
  end
@@ -355,8 +365,7 @@ module Traject
355
365
  record_batch.clear
356
366
 
357
367
  rescue Exception => e
358
- logger.fatal "HorizonReader, unexpected exception at bib id:#{current_bib_id}: #{Traject::Util.exception_to_log_message(e)}"
359
- logger.fatal e.backtrace.join("/n")
368
+ logger.fatal "HorizonReader, unexpected exception at bib id:#{current_bib_id}: #{e}"
360
369
  raise e
361
370
  ensure
362
371
  logger.info("HorizonReader: Closing all JDBC objects...")
@@ -623,16 +632,36 @@ module Traject
623
632
  settings['horizon.source_encoding'] == "MARC8" && settings['horizon.destination_encoding'] == "UTF8"
624
633
  end
625
634
 
635
+ # Looks up JDBC url from settings, either 'horizon.jdbc_url' if present,
636
+ # or individual settings. Will include password from `horizon.password`
637
+ # only if given a `true` arg -- leave false for output to logs, to keep
638
+ # password out of logs.
639
+ def jdbc_url(include_password=false)
640
+ url = if settings.has_key? "horizon.jdbc_url"
641
+ settings["horizon.jdbc_url"]
642
+ else
643
+ jtds_type = settings['horizon.jtds_type'] || 'sybase'
644
+ database = settings['horizon.database'] || 'horizon'
645
+ host = settings['horizon.host'] or raise ArgumentError.new("Need horizon.host setting, or horizon.jdbc_url")
646
+ port = settings['horizon.port'] || '2025'
647
+ user = settings['horizon.user'] or raise ArgumentError.new("Need horizon.user setting, or horizon.jdbc_url")
626
648
 
627
- def open_connection!
628
- logger.debug("HorizonReader: Opening JDBC Connection at #{settings["horizon.jdbc_url"]} ...")
649
+ "jdbc:jtds:#{jtds_type}://#{host}:#{port}/#{database};user=#{user}"
650
+ end
629
651
 
630
- url = settings["horizon.jdbc_url"]
631
- if settings["horizon.jdbc_password"]
632
- url += ";password=#{settings['horizon.jdbc_password']}"
652
+ if include_password
653
+ password = settings['horizon.password'] or raise ArgumentError.new("Need horizon.password setting")
654
+ url += ";password=#{password}"
633
655
  end
634
656
 
635
- conn = java.sql.DriverManager.getConnection( url )
657
+ return url
658
+ end
659
+
660
+
661
+ def open_connection!
662
+ logger.debug("HorizonReader: Opening JDBC Connection at #{jdbc_url(false)} ...")
663
+
664
+ conn = java.sql.DriverManager.getConnection( jdbc_url(true) )
636
665
  # If autocommit on, fetchSize later has no effect, and JDBC slurps
637
666
  # the whole result set into memory, which we can not handle.
638
667
  conn.setAutoCommit false
@@ -1,3 +1,3 @@
1
1
  module TrajectHorizon
2
- VERSION = "0.11.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,21 @@
1
+ # Encoding: UTF-8
2
+
3
+ require 'test_helper'
4
+
5
+ require 'traject'
6
+ require 'traject/horizon_reader'
7
+
8
+ describe "turning weird Horizon escape sequences into unicode" do
9
+ describe "convert_text" do
10
+ before do
11
+ @reader = Traject::HorizonReader.new(nil, {"horizon.host" => "example.com", "horizon.user" => "dummy"})
12
+ end
13
+
14
+ it "converts" do
15
+ converted = @reader.convert_text!("A hangul character: <U+1112>, okay<!>", org.marc4j.ErrorHandler.new)
16
+ assert_equal "A hangul character: ᄒ, okay<!>", converted
17
+ end
18
+
19
+ end
20
+
21
+ end
metadata CHANGED
@@ -1,97 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traject_horizon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jonathan Rochkind
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-24 00:00:00.000000000 Z
11
+ date: 2013-10-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: traject
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
15
+ version_requirements: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
20
+ requirement: !ruby/object:Gem::Requirement
26
21
  requirements:
27
- - - ! '>='
22
+ - - '>='
28
23
  - !ruby/object:Gem::Version
29
24
  version: '0'
25
+ prerelease: false
26
+ type: :runtime
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: marc-marc4j
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
29
+ version_requirements: !ruby/object:Gem::Requirement
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
34
+ requirement: !ruby/object:Gem::Requirement
42
35
  requirements:
43
- - - ! '>='
36
+ - - '>='
44
37
  - !ruby/object:Gem::Version
45
38
  version: '0'
39
+ prerelease: false
40
+ type: :runtime
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
43
+ version_requirements: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
53
47
  version: '1.3'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
48
+ requirement: !ruby/object:Gem::Requirement
58
49
  requirements:
59
50
  - - ~>
60
51
  - !ruby/object:Gem::Version
61
52
  version: '1.3'
53
+ prerelease: false
54
+ type: :development
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
57
+ version_requirements: !ruby/object:Gem::Requirement
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
62
+ requirement: !ruby/object:Gem::Requirement
74
63
  requirements:
75
- - - ! '>='
64
+ - - '>='
76
65
  - !ruby/object:Gem::Version
77
66
  version: '0'
67
+ prerelease: false
68
+ type: :development
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: minitest
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
71
+ version_requirements: !ruby/object:Gem::Requirement
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
76
+ requirement: !ruby/object:Gem::Requirement
90
77
  requirements:
91
- - - ! '>='
78
+ - - '>='
92
79
  - !ruby/object:Gem::Version
93
80
  version: '0'
94
- description:
81
+ prerelease: false
82
+ type: :development
83
+ description:
95
84
  email:
96
85
  - jonathan@dnil.net
97
86
  executables: []
@@ -108,6 +97,7 @@ files:
108
97
  - lib/traject_horizon.rb
109
98
  - lib/traject_horizon/version.rb
110
99
  - test/horizon_bib_auth_merge_test.rb
100
+ - test/horizon_unicode_escape_test.rb
111
101
  - test/test_helper.rb
112
102
  - traject_horizon.gemspec
113
103
  - vendor/jtds/.DS_Store
@@ -115,28 +105,28 @@ files:
115
105
  homepage: http://github.com/jrochkind/traject_horizon
116
106
  licenses:
117
107
  - MIT
118
- post_install_message:
108
+ metadata: {}
109
+ post_install_message:
119
110
  rdoc_options: []
120
111
  require_paths:
121
112
  - lib
122
113
  required_ruby_version: !ruby/object:Gem::Requirement
123
- none: false
124
114
  requirements:
125
- - - ! '>='
115
+ - - '>='
126
116
  - !ruby/object:Gem::Version
127
117
  version: '0'
128
118
  required_rubygems_version: !ruby/object:Gem::Requirement
129
- none: false
130
119
  requirements:
131
- - - ! '>='
120
+ - - '>='
132
121
  - !ruby/object:Gem::Version
133
122
  version: '0'
134
123
  requirements: []
135
- rubyforge_project:
136
- rubygems_version: 1.8.23
137
- signing_key:
138
- specification_version: 3
124
+ rubyforge_project:
125
+ rubygems_version: 2.1.5
126
+ signing_key:
127
+ specification_version: 4
139
128
  summary: Horizon ILS MARC Exporter, a plugin for the traject tool
140
129
  test_files:
141
130
  - test/horizon_bib_auth_merge_test.rb
131
+ - test/horizon_unicode_escape_test.rb
142
132
  - test/test_helper.rb