berkeley_library-tind 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/tind.iml +7 -7
- data/.rubocop.yml +1 -1
- data/CHANGES.md +10 -2
- data/README.md +50 -6
- data/berkeley_library-tind.gemspec +1 -2
- data/lib/berkeley_library/tind/export/ods_exporter.rb +4 -6
- data/lib/berkeley_library/tind/mapping/alma_base.rb +7 -0
- data/lib/berkeley_library/tind/mapping/data/one_to_one_mapping.csv +39 -39
- data/lib/berkeley_library/tind/mapping/field_catalog.rb +2 -11
- data/lib/berkeley_library/tind/mapping/field_catalog_util.rb +49 -3
- data/lib/berkeley_library/tind/mapping/single_rule.rb +6 -0
- data/lib/berkeley_library/tind/mapping/tind_field_from_single_map.rb +13 -1
- data/lib/berkeley_library/tind/mapping/tind_record_util.rb +135 -0
- data/lib/berkeley_library/tind/mapping/util.rb +19 -0
- data/lib/berkeley_library/tind/module_info.rb +1 -1
- data/spec/berkeley_library/tind/mapping/alma_multiple_tind_spec.rb +1 -1
- data/spec/berkeley_library/tind/mapping/alma_single_tind_spec.rb +1 -1
- data/spec/berkeley_library/tind/mapping/field_catalog_util_spec.rb +48 -0
- data/spec/berkeley_library/tind/mapping/match_tind_field_spec.rb +1 -2
- data/spec/berkeley_library/tind/mapping/tind_field_from_single_map_spec.rb +17 -0
- data/spec/berkeley_library/tind/mapping/tind_record_util_spec.rb +30 -0
- data/spec/data/api/pre_assigned_response.json +15 -0
- data/spec/data/api/result_file.csv +3 -0
- data/spec/data/api/upload_file.json +1 -0
- data/spec/data/api/upload_response.json +13 -0
- data/spec/data/mapping/record.xml +6 -3
- metadata +15 -83
- data/lib/berkeley_library/util/files.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e02344bc1a5d5c119c860bd357dfac55753bc809149cef7a068941f0566682c
|
4
|
+
data.tar.gz: aaba20e6650860ef0d89619522264746f1e689800e20abde0247ca0a3c55bad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c83767367a893dd418c47bc1a74e5d2bf362bceeb009af7427a5e1f240dd4cb5ab57b8c032295e6e253dd5f71f5b512fd2bf112b1734a80d22d62a06b92d6c28
|
7
|
+
data.tar.gz: 224863c5c06224dbc4c2caae4e73c7f1752ee1f5303a758af1428667a938bb561a2d97e0a31306627cd37325e4518d4f674e22d270f2bcd40e631b90265eb62f
|
data/.idea/tind.iml
CHANGED
@@ -9,16 +9,16 @@
|
|
9
9
|
</content>
|
10
10
|
<orderEntry type="jdk" jdkName="RVM: ruby-2.7.5" jdkType="RUBY_SDK" />
|
11
11
|
<orderEntry type="sourceFolder" forTests="false" />
|
12
|
-
<orderEntry type="library" scope="PROVIDED" name="actionpack (v7.0.2.
|
13
|
-
<orderEntry type="library" scope="PROVIDED" name="actionview (v7.0.2.
|
14
|
-
<orderEntry type="library" scope="PROVIDED" name="activesupport (v7.0.2.
|
12
|
+
<orderEntry type="library" scope="PROVIDED" name="actionpack (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
13
|
+
<orderEntry type="library" scope="PROVIDED" name="actionview (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
15
15
|
<orderEntry type="library" scope="PROVIDED" name="addressable (v2.8.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
16
16
|
<orderEntry type="library" scope="PROVIDED" name="amazing_print (v1.4.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
17
17
|
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
18
18
|
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-alma (v0.0.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
19
19
|
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-logging (v0.2.6, RVM: ruby-2.7.5) [gem]" level="application" />
|
20
20
|
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-marc (v0.3.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
21
|
-
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-util (v0.1.
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="berkeley_library-util (v0.1.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
22
22
|
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
23
23
|
<orderEntry type="library" scope="PROVIDED" name="bundle-audit (v0.1.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
24
24
|
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.31, RVM: ruby-2.7.5) [gem]" level="application" />
|
@@ -41,14 +41,14 @@
|
|
41
41
|
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.10.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
42
42
|
<orderEntry type="library" scope="PROVIDED" name="ice_nine (v0.11.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
43
43
|
<orderEntry type="library" scope="PROVIDED" name="lograge (v0.12.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
44
|
-
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.17.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
45
45
|
<orderEntry type="library" scope="PROVIDED" name="marc (v1.1.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
46
46
|
<orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
47
47
|
<orderEntry type="library" scope="PROVIDED" name="mime-types (v3.4.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
48
48
|
<orderEntry type="library" scope="PROVIDED" name="mime-types-data (v3.2022.0105, RVM: ruby-2.7.5) [gem]" level="application" />
|
49
49
|
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
50
50
|
<orderEntry type="library" scope="PROVIDED" name="netrc (v0.11.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
51
|
-
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.13.5, RVM: ruby-2.7.5) [gem]" level="application" />
|
52
52
|
<orderEntry type="library" scope="PROVIDED" name="oj (v3.13.11, RVM: ruby-2.7.5) [gem]" level="application" />
|
53
53
|
<orderEntry type="library" scope="PROVIDED" name="ougai (v1.9.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
54
54
|
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.21.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
@@ -60,7 +60,7 @@
|
|
60
60
|
<orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
61
61
|
<orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, RVM: ruby-2.7.5) [gem]" level="application" />
|
62
62
|
<orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.2, RVM: ruby-2.7.5) [gem]" level="application" />
|
63
|
-
<orderEntry type="library" scope="PROVIDED" name="railties (v7.0.2.
|
63
|
+
<orderEntry type="library" scope="PROVIDED" name="railties (v7.0.2.4, RVM: ruby-2.7.5) [gem]" level="application" />
|
64
64
|
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, RVM: ruby-2.7.5) [gem]" level="application" />
|
65
65
|
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-2.7.5) [gem]" level="application" />
|
66
66
|
<orderEntry type="library" scope="PROVIDED" name="rchardet (v1.8.0, RVM: ruby-2.7.5) [gem]" level="application" />
|
data/.rubocop.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,10 +1,18 @@
|
|
1
|
-
# 0.
|
1
|
+
# 0.7.0 (2022-10-26)
|
2
|
+
|
3
|
+
- Preserves subfield order insofar as possible when mapping Alma records to TIND.
|
4
|
+
- Adds collection-specific configuration for mapping Alma records to TIND.
|
5
|
+
- Adds `BerkeleyLibrary::TIND::Mapping::TindRecordUtil` class for manipulating
|
6
|
+
subfields in TIND MARC records.
|
7
|
+
- Removes `BerkeleyLibrary::Util::Files` class, which is now part of `berkeley_library-util`.
|
8
|
+
|
9
|
+
# 0.6.0 (2022-04-06)
|
2
10
|
|
3
11
|
- Adds `BerkeleyLibrary::TIND::Mapping` module to map MARC records from Alma to TIND.
|
4
12
|
- `BerkeleyLibrary::TIND::MARC::XMLWriter` now assumes that any object that response to `:write`
|
5
13
|
and `:close` is suffiently `IO`-like to write to.
|
6
14
|
|
7
|
-
# 0.5.1 (
|
15
|
+
# 0.5.1 (2022-03-23)
|
8
16
|
|
9
17
|
- Fix an issue where `BerkeleyLibrary::TIND::MARC::XMLWriter` would drop fields with nonstandard tags (e.g. `FFT` fields)
|
10
18
|
and would group and sort fields by tag instead of preserving the original order.
|
data/README.md
CHANGED
@@ -45,10 +45,10 @@ string setting will raise `URI::InvalidURIError`.
|
|
45
45
|
|
46
46
|
### Alma configuration
|
47
47
|
|
48
|
-
When mapping Alma records to TIND (see below), this gem uses
|
48
|
+
When mapping Alma records to TIND (see below), this gem uses
|
49
49
|
[`berkeley_library-alma`](https://github.com/BerkeleyLibrary/alma) to load
|
50
50
|
Alma records. The scripts in the `bin` directory use the default Alma
|
51
|
-
configuration; see the `berkeley_library-alma`
|
51
|
+
configuration; see the `berkeley_library-alma`
|
52
52
|
[README](https://github.com/BerkeleyLibrary/alma#configuration) for
|
53
53
|
details.
|
54
54
|
|
@@ -127,7 +127,8 @@ variable are set for either, the explicit option takes precedence.
|
|
127
127
|
### Example
|
128
128
|
|
129
129
|
1. Setup collection information
|
130
|
-
|
130
|
+
|
131
|
+
Include below collection level fields:
|
131
132
|
- 336: type of resource
|
132
133
|
- 852: collection's repository name
|
133
134
|
- 980: collection's 980 value
|
@@ -137,6 +138,7 @@ variable are set for either, the explicit option takes precedence.
|
|
137
138
|
``` ruby
|
138
139
|
|
139
140
|
def setup_collection
|
141
|
+
# 1. Define collection level field information
|
140
142
|
BerkeleyLibrary::TIND::Mapping::AlmaBase.collection_parameter_hash = {
|
141
143
|
'336' => ['Image'],
|
142
144
|
'852' => ['East Asian Library'],
|
@@ -144,11 +146,27 @@ def setup_collection
|
|
144
146
|
'982' => ['Pre 1912 Chinese Materials - short name', 'Pre 1912 Chinese Materials - long name'],
|
145
147
|
'991' => []
|
146
148
|
}
|
147
|
-
|
149
|
+
|
150
|
+
# 2. A flag to include a pre-defined 035 formated in "(980__$a)mms_id",
|
151
|
+
# the default value is 'false'
|
148
152
|
# BerkeleyLibrary::TIND::Mapping::AlmaBase.is_035_from_mms_id = true
|
149
153
|
|
150
|
-
#
|
151
|
-
BerkeleyLibrary::TIND::Mapping::AlmaBase.is_barcode = true
|
154
|
+
# 3. A flag on getting Alma record using Barcode, the defalut value is 'false'
|
155
|
+
# BerkeleyLibrary::TIND::Mapping::AlmaBase.is_barcode = true
|
156
|
+
|
157
|
+
# 4. Define a list of origin tags from an Alma record.
|
158
|
+
# Only those related fields (including 880 fields) will be mapped to a TIND record.
|
159
|
+
# The default value is []. '001', '008' will be included by default, no need to be listed here.
|
160
|
+
# BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[256]
|
161
|
+
|
162
|
+
# 5. Define a list of origin tags from an Alma record which will be excluded during mapping.
|
163
|
+
# The default value is []
|
164
|
+
# 1) When the list includes an 880 tag, all 880 fields will be excluded
|
165
|
+
# 2) When the list has no 880 tag, only related 880 fields will be excludded
|
166
|
+
# BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = %w[245 700]
|
167
|
+
|
168
|
+
# 6. Not allow to define both #5 and #6. Returning empty fields when defining both #5 and #6
|
169
|
+
|
152
170
|
end
|
153
171
|
```
|
154
172
|
|
@@ -204,3 +222,29 @@ alma_tind = BerkeleyLibrary::TIND::Mapping::AlmaMultipleTIND.new(id)
|
|
204
222
|
tind_record_1 = alma_tind.record(additional_tind_fields_1)
|
205
223
|
tind_record_2 = alma_tind.record(additional_tind_fields_2)
|
206
224
|
```
|
225
|
+
|
226
|
+
5. Updating TIND record with TindRecordUtil : 1) add/update subfields to one-occurrenced field; 2) remove fields.
|
227
|
+
|
228
|
+
``` ruby
|
229
|
+
# 5.1 This is an example hash for updating/adding subfields.
|
230
|
+
tag_subfield_hash = { '245' => { 'b' => 'subtitle', 'a' => 'title' }, '336' => { 'a' => 'Audio' }, '246' => {'a' => nil}}
|
231
|
+
|
232
|
+
# if 245__$b existed, it will be replaced it with 'subtitle';
|
233
|
+
# otherwise, adding a new 245__$b subfield with value 'subtile';
|
234
|
+
# '246' => {'a' => nil}, since value is nil, it won't add/update 246__$a
|
235
|
+
|
236
|
+
# 5.2 This is an example array of removing fields.
|
237
|
+
fields_removal_list = [%w[856 4 1] %w[260 _ _]]
|
238
|
+
|
239
|
+
# Each item includes field information: [tag, indicator1, indictor2].
|
240
|
+
# if indicator is empty, using '_'
|
241
|
+
|
242
|
+
# How to use it:
|
243
|
+
# a. add/update subfields of existed fields in a TIND Marc record:
|
244
|
+
new_record = BerkeleyLibrary::TIND::Mapping::TindRecordUtil.update_record(record, tag_subfield_hash)
|
245
|
+
# b. remove a list of fields in a TIND Marc record:
|
246
|
+
new_record = BerkeleyLibrary::TIND::Mapping::TindRecordUtil.update_record(record, nil, fields_removal_list)
|
247
|
+
# c. both a. and b. :
|
248
|
+
new_record = BerkeleyLibrary::TIND::Mapping::TindRecordUtil.update_record(record, tag_subfield_hash, fields_removal_list)
|
249
|
+
|
250
|
+
```
|
@@ -17,7 +17,6 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.homepage = BerkeleyLibrary::TIND::ModuleInfo::HOMEPAGE
|
18
18
|
|
19
19
|
spec.files = `git ls-files -z`.split("\x0")
|
20
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
20
|
spec.require_paths = ['lib']
|
22
21
|
spec.executables << 'tind-export'
|
23
22
|
|
@@ -26,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
26
25
|
spec.add_dependency 'berkeley_library-alma', '~> 0.0.1'
|
27
26
|
spec.add_dependency 'berkeley_library-logging', '~> 0.2'
|
28
27
|
spec.add_dependency 'berkeley_library-marc', '~> 0.3.0', '>= 0.3.1'
|
29
|
-
spec.add_dependency 'berkeley_library-util', '~> 0.1'
|
28
|
+
spec.add_dependency 'berkeley_library-util', '~> 0.1', '>= 0.1.2'
|
30
29
|
spec.add_dependency 'ice_nine', '~> 0.11'
|
31
30
|
spec.add_dependency 'marc', '~> 1.0'
|
32
31
|
spec.add_dependency 'rchardet', '~> 1.8'
|
@@ -67,12 +67,10 @@ module BerkeleyLibrary
|
|
67
67
|
|
68
68
|
def header_cell_style_for(col_index)
|
69
69
|
@header_cell_styles ||= []
|
70
|
-
@header_cell_styles[col_index] ||=
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
)
|
75
|
-
end
|
70
|
+
@header_cell_styles[col_index] ||= find_or_create_cell_style(
|
71
|
+
color: color_for(col_index),
|
72
|
+
font_weight: 'bold'
|
73
|
+
)
|
76
74
|
end
|
77
75
|
|
78
76
|
def find_or_create_cell_style(color:, font_weight: nil, wrap: false)
|
@@ -9,11 +9,16 @@ module BerkeleyLibrary
|
|
9
9
|
@collection_parameter_hash = {}
|
10
10
|
@is_barcode = false
|
11
11
|
@is_035_from_mms_id = false
|
12
|
+
@including_origin_tags = []
|
13
|
+
@excluding_origin_tags = []
|
12
14
|
|
13
15
|
class << self
|
14
16
|
attr_accessor :collection_parameter_hash
|
15
17
|
attr_accessor :is_barcode
|
16
18
|
attr_accessor :is_035_from_mms_id
|
19
|
+
attr_accessor :including_origin_tags
|
20
|
+
attr_accessor :excluding_origin_tags
|
21
|
+
|
17
22
|
end
|
18
23
|
|
19
24
|
# id can be:
|
@@ -74,6 +79,8 @@ module BerkeleyLibrary
|
|
74
79
|
end
|
75
80
|
|
76
81
|
def tind_record(id, marc_record, datafields)
|
82
|
+
return nil unless Util.collection_config_correct?
|
83
|
+
|
77
84
|
tindmarc = TindMarc.new(marc_record)
|
78
85
|
# get all derived tind_fields: 1) from collection information; 2) from id
|
79
86
|
mms_id = tindmarc.field_catalog.mms_id
|
@@ -1,39 +1,39 @@
|
|
1
|
-
tag_origin,tag_destination,subfield_single_from,subfield_single_to,subfield_combined_from_1,subfield_combined_to_1,symbol_1 ,subfield_combined_from_2,subfield_combined_to_2,symbol_2,subfield_combined_from_3,subfield_combined_to_3,symbol_3,New_indecator,Position_from,Position_to,Map_if_no_this_tag_existed,Map_if_no_this_tag_subfield_existed, Keep_one_if_multiple_available
|
2
|
-
100,700,"6,e","6,e","a,b,c,d,q",a,,,,,,,,"1,_",,,,,
|
3
|
-
110,710,"6,e","6,e","a,b",a,,,,,,,,"2,_",,,,,
|
4
|
-
111,711,6,6
|
5
|
-
242,246,6,6
|
6
|
-
245,245,"6,a","6,a","n,p",p,,,,,"b,f,k",b,,"_,_",,,,,
|
7
|
-
246,246,6,6
|
8
|
-
250,250,"6,a","6,a"
|
9
|
-
255,255,"6,a,b,c","6,a,b,c"
|
10
|
-
260,260,"6,a,b,c","6,a,b,c"
|
11
|
-
264,260,"6,a,b,c","6,a,b,c"
|
12
|
-
300,300,"6,b,c","6,b,c","3,a",a,,,,,,,,"_,_",,,,,
|
13
|
-
351,505,6,6
|
14
|
-
490,490,6,6
|
15
|
-
500,500,"6,a","6,a"
|
16
|
-
502,502,6,6
|
17
|
-
505,505,6,6
|
18
|
-
507,255,"6,a","6,a"
|
19
|
-
520,520,"6,a","6,a"
|
20
|
-
522,522,"6,a","6,a"
|
21
|
-
524,524,"6,a","6,a"
|
22
|
-
536,536,"6,a","6,a"
|
23
|
-
541,541,6,6
|
24
|
-
545,545,"6,a","6,a"
|
25
|
-
546,546,"6,a","6,a"
|
26
|
-
600,600,6,6
|
27
|
-
610,610,6,6
|
28
|
-
611,611,6,6
|
29
|
-
630,630,6,6
|
30
|
-
650,650,6,6
|
31
|
-
651,651,6,6
|
32
|
-
655,655,"6,2","6,2"
|
33
|
-
700,700,"6,e","6,e","a,b,c,d,q",a,,,,,,,,"1,_",,,,,
|
34
|
-
710,710,"6,e","6,e","a,b",a,,,,,,,,"2,_",,,,,
|
35
|
-
711,711,6,6
|
36
|
-
720,700,"6,a,e","6,a,e"
|
37
|
-
752,651,6,6
|
38
|
-
773,773,"6,t,j,k,o","6,t,j,k,o"
|
39
|
-
907,901,"6,a","6,m"
|
1
|
+
tag_origin,tag_destination,subfield_single_from,subfield_single_to,order,subfield_combined_from_1,subfield_combined_to_1,symbol_1 ,subfield_combined_from_2,subfield_combined_to_2,symbol_2,subfield_combined_from_3,subfield_combined_to_3,symbol_3,New_indecator,Position_from,Position_to,Map_if_no_this_tag_existed,Map_if_no_this_tag_subfield_existed, Keep_one_if_multiple_available
|
2
|
+
100,700,"6,e","6,e","6,a,e","a,b,c,d,q",a,,,,,,,,"1,_",,,,,
|
3
|
+
110,710,"6,e","6,e","6,a,e","a,b",a,,,,,,,,"2,_",,,,,
|
4
|
+
111,711,6,6,,"a,c,d,e,f,n,p,t",a,,,,,,,,"_,_",,,,,
|
5
|
+
242,246,6,6,,"a,b,p,n",a,,,,,,,,,,,,,
|
6
|
+
245,245,"6,a","6,a","6,a,b,p","n,p",p,,,,,"b,f,k",b,,"_,_",,,,,
|
7
|
+
246,246,6,6,,"a,b,p,n",a,,,,,,,,"_,_",,,,,
|
8
|
+
250,250,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
9
|
+
255,255,"6,a,b,c","6,a,b,c",,,,,,,,,,,"_,_",,,,,
|
10
|
+
260,260,"6,a,b,c","6,a,b,c",,,,,,,,,,,"_,_",,,,,
|
11
|
+
264,260,"6,a,b,c","6,a,b,c",,,,,,,,,,,"_,_",,,260,,1
|
12
|
+
300,300,"6,b,c","6,b,c","6,a,b,c","3,a",a,,,,,,,,"_,_",,,,,
|
13
|
+
351,505,6,6,,"a,b",a,,,,,,,,"_,_",,,,,
|
14
|
+
490,490,6,6,,"a,v",a,,,,,,,,"_,_",,,,,
|
15
|
+
500,500,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
16
|
+
502,502,6,6,,"a,b,c,d,g,o",a,,,,,,,,"_,_",,,,,
|
17
|
+
505,505,6,6,,"a,g,r,t",a,,,,,,,,"_,_",,,,,
|
18
|
+
507,255,"6,a","6,a",,,,,,,,,,,"_,_",,,,255__a,
|
19
|
+
520,520,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
20
|
+
522,522,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
21
|
+
524,524,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
22
|
+
536,536,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
23
|
+
541,541,6,6,,"c,a,d",a,,,,,,,,"_,_",,,,,
|
24
|
+
545,545,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
25
|
+
546,546,"6,a","6,a",,,,,,,,,,,"_,_",,,,,
|
26
|
+
600,600,6,6,,"a,b,c,d,f,j,k,l,m,n,o,p,q,r,s,t",a,,"x,y,z,v",a,a--a,,,,"_,_",,,,,
|
27
|
+
610,610,6,6,,"a,b,c,d,f,j,k,l,m,n,o,p,q,r,s,t",a,,"x,y,z,v",a,a--a,,,,"_,_",,,,,
|
28
|
+
611,611,6,6,,"a,b,c,d,f,j,k,l,m,n,o,p,q,r,s,t",a,,"x,y,z,v",a,a--a,,,,"_,_",,,,,
|
29
|
+
630,630,6,6,,"a,b,c,d,f,j,k,l,m,n,o,p,q,r,s,t",a,,"x,y,z,v",a,a--a,,,,"_,_",,,,,
|
30
|
+
650,650,6,6,,"a,b,c",a,,"x,y,z,v",a,a--a,,,,"_,_",,,,,
|
31
|
+
651,651,6,6,,a,a,,"x,y,z,v",a,a--a,,,,"_,_",,,,,
|
32
|
+
655,655,"6,2","6,2",,a,a,,"x,y,z,v",a,a--a,,,,"_,_",,,,,
|
33
|
+
700,700,"6,e","6,e","6,a,e","a,b,c,d,q",a,,,,,,,,"1,_",,,,,
|
34
|
+
710,710,"6,e","6,e","6,a,e","a,b",a,,,,,,,,"2,_",,,,,
|
35
|
+
711,711,6,6,,"a,c,d,e,f,n,p,t",a,,,,,,,,"_,_",,,,,
|
36
|
+
720,700,"6,a,e","6,a,e",,,,,,,,,,,"1,_",,,,,
|
37
|
+
752,651,6,6,,,,,"a,b,c,d,f,g",a,a--a,,,,"_,_",,,,,
|
38
|
+
773,773,"6,t,j,k,o","6,t,j,k,o",,,,,,,,,,,"_,_",,,,,
|
39
|
+
907,901,"6,a","6,m",,,,,,,,,,,"_,_",,,,,
|
@@ -47,7 +47,8 @@ module BerkeleyLibrary
|
|
47
47
|
def prepare_catalog(record)
|
48
48
|
clean_fields = clean_subfields(record.fields)
|
49
49
|
check_abnormal_formated_subfield6(clean_fields)
|
50
|
-
|
50
|
+
final_fields_to_map = fields_to_map(clean_fields)
|
51
|
+
allocate_fields(final_fields_to_map)
|
51
52
|
remove_fields_with_subject_fast
|
52
53
|
end
|
53
54
|
|
@@ -115,16 +116,6 @@ module BerkeleyLibrary
|
|
115
116
|
# If tag is listed in csv_mapper.one_occurrence_tags
|
116
117
|
# Check pre_existed field of this tag
|
117
118
|
# make sure to keep the first datafield for an one_occurrence_tag defined in csv mapping file
|
118
|
-
# def no_pre_existed_field?(tag)
|
119
|
-
# # no one-occurrence defined in csv
|
120
|
-
# return true unless one_occurrence_tags.include? tag
|
121
|
-
|
122
|
-
# # Checking the exsisting regular fields include the one-occurrence field defined in the csv
|
123
|
-
# return false if @alma_field_tags.compact.include? tag
|
124
|
-
|
125
|
-
# true
|
126
|
-
# end
|
127
|
-
|
128
119
|
def no_pre_existed_field?(tag)
|
129
120
|
# no one-occurrence defined in csv
|
130
121
|
return true unless one_occurrence_tags.include? tag
|
@@ -1,7 +1,10 @@
|
|
1
|
+
require 'berkeley_library/tind/mapping/alma_base'
|
2
|
+
|
1
3
|
module BerkeleyLibrary
|
2
4
|
module TIND
|
3
5
|
module Mapping
|
4
6
|
module FieldCatalogUtil
|
7
|
+
include AlmaBase
|
5
8
|
|
6
9
|
# Excluding fields: subfield2 = 'fast' and tag or refered tag(880 fields) started with '6':
|
7
10
|
def exluding_fields_with_fast_subject(fields)
|
@@ -17,14 +20,56 @@ module BerkeleyLibrary
|
|
17
20
|
|
18
21
|
rule = rules[Util.tag_symbol(tag)]
|
19
22
|
|
20
|
-
|
23
|
+
assign_field(rule, f, datafields_hash)
|
21
24
|
end
|
22
25
|
|
23
26
|
datafields_hash
|
24
27
|
end
|
25
28
|
|
29
|
+
# Defining a list of fields from Alma to be mapped to TIND fields based on
|
30
|
+
# collection configuration:
|
31
|
+
# 1) BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags
|
32
|
+
# 2) BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags
|
33
|
+
def fields_to_map(fields)
|
34
|
+
including_defined = !BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags.empty?
|
35
|
+
excluding_defined = !BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags.empty?
|
36
|
+
return [] if including_defined && excluding_defined # not allow to define both including and excluding tags
|
37
|
+
return fields unless including_defined || excluding_defined # Neither including nor excluding tags are defined
|
38
|
+
return fields_included(fields) if including_defined # including tags defined
|
39
|
+
return fields_exclued(fields) if excluding_defined # excluding tags defined
|
40
|
+
end
|
41
|
+
|
26
42
|
private
|
27
43
|
|
44
|
+
def fields_included(fields)
|
45
|
+
fields.select { |f| inclduing?(f) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def inclduing?(f)
|
49
|
+
return true if %w[001 008].include? f.tag # always keeping 001, 008 field since it include almid
|
50
|
+
|
51
|
+
tag = origin_mapping_tag(f)
|
52
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags.include? tag
|
53
|
+
end
|
54
|
+
|
55
|
+
def fields_exclued(fields)
|
56
|
+
new_fields = []
|
57
|
+
exclude_tags = BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags
|
58
|
+
fields.each do |f|
|
59
|
+
tag = tag(f, exclude_tags)
|
60
|
+
new_fields << f unless exclude_tags.include? tag
|
61
|
+
end
|
62
|
+
new_fields
|
63
|
+
end
|
64
|
+
|
65
|
+
# 1. exluding tags have '880' : all 880 fields will be excluded
|
66
|
+
# 2. excluding tags have no '880', then excluding 880 fields whoses refered tag located in excluding tags
|
67
|
+
def tag(field, exclude_tags)
|
68
|
+
return field.tag if exclude_tags.include? '880' # Case: excluding all 880 fields
|
69
|
+
|
70
|
+
origin_mapping_tag(field)
|
71
|
+
end
|
72
|
+
|
28
73
|
def excluding_field?(f)
|
29
74
|
return false unless field_6xx?(f)
|
30
75
|
return false unless subfield2_fast(f)
|
@@ -46,10 +91,11 @@ module BerkeleyLibrary
|
|
46
91
|
end
|
47
92
|
|
48
93
|
# f is either from field whose tag having a match in csv mapping file - 'from tag' column
|
49
|
-
def
|
94
|
+
def assign_field(rule, f, datafields_hash)
|
50
95
|
if rule.pre_existed_tag then datafields_hash[:pre_tag] << f
|
51
96
|
elsif rule.pre_existed_tag_subfield then datafields_hash[:pre_tag_subfield] << f
|
52
|
-
else
|
97
|
+
else
|
98
|
+
datafields_hash[:normal] << f
|
53
99
|
end
|
54
100
|
end
|
55
101
|
|
@@ -26,6 +26,7 @@ module BerkeleyLibrary
|
|
26
26
|
attr_reader :single_rule_hash
|
27
27
|
attr_reader :single_rule_subfield_excluded_hash
|
28
28
|
attr_reader :combined_rules
|
29
|
+
attr_reader :subfields_order
|
29
30
|
|
30
31
|
def initialize(row)
|
31
32
|
@tag_origin = row[:tag_origin]
|
@@ -36,6 +37,7 @@ module BerkeleyLibrary
|
|
36
37
|
@single_rule_hash = single_map_dic(row[:subfield_single_from], row[:subfield_single_to])
|
37
38
|
@single_rule_subfield_excluded_hash = single_map_subfield_excluded_dic
|
38
39
|
@combined_rules = rules_with_same_subfield_name(row)
|
40
|
+
@subfields_order = order(row[:order])
|
39
41
|
end
|
40
42
|
|
41
43
|
# 1. Return an array of combined rules, an item in the array
|
@@ -51,6 +53,10 @@ module BerkeleyLibrary
|
|
51
53
|
|
52
54
|
private
|
53
55
|
|
56
|
+
def order(str)
|
57
|
+
str.nil? ? nil : str.split(',')
|
58
|
+
end
|
59
|
+
|
54
60
|
# return an array of tag and subfield name, example '255__a' => ['255','a']
|
55
61
|
def existed_tag_subfield(str)
|
56
62
|
str.nil? ? nil : str.split('__')
|
@@ -39,6 +39,7 @@ module BerkeleyLibrary
|
|
39
39
|
@single_mapping = nil
|
40
40
|
@ready_to_mapping = ready_to_mapping?
|
41
41
|
|
42
|
+
@codes = subfield_codes(@from_datafield)
|
42
43
|
@to_subfields = all_subfields
|
43
44
|
end
|
44
45
|
|
@@ -82,7 +83,18 @@ module BerkeleyLibrary
|
|
82
83
|
end
|
83
84
|
|
84
85
|
def all_subfields
|
85
|
-
|
86
|
+
return [] unless @ready_to_mapping
|
87
|
+
|
88
|
+
subfields = subfields_from_single_map + subfields_from_combined_map
|
89
|
+
codes = @mapping_rule.subfields_order || @codes
|
90
|
+
|
91
|
+
return subfields unless subfields.length > 1
|
92
|
+
|
93
|
+
Util.order_subfields(subfields, codes)
|
94
|
+
end
|
95
|
+
|
96
|
+
def subfield_codes(f)
|
97
|
+
f.subfields.map(&:code).uniq
|
86
98
|
end
|
87
99
|
|
88
100
|
# 1.subfields mapped with single rule, mapping one subfield to another subfield
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'marc'
|
2
|
+
|
3
|
+
module BerkeleyLibrary
|
4
|
+
module TIND
|
5
|
+
module Mapping
|
6
|
+
module TindRecordUtil
|
7
|
+
|
8
|
+
class << self
|
9
|
+
include TindRecordUtil
|
10
|
+
end
|
11
|
+
|
12
|
+
# 1) tag_subfield_hash: a hash to add a new, or update an existing subfield to a field in a TIND Marc record
|
13
|
+
# If a subfield existed, it will replace the subfield, otherwise, add a new subfield
|
14
|
+
# when 'a' => nil, it will skip add/update to subfield,
|
15
|
+
# It can be useed in a case: only need to add/update subfields of specific records in a collection
|
16
|
+
# This is an example: tag_subfield_hash = { '245' => { 'b' => 'subtitle', 'a' => 'title' }, '336' => { 'a' => nil } }
|
17
|
+
# 2) fields_removal_list: an array including fields' informat: tag, indicators - "[tag, inicator1, indicator2]".
|
18
|
+
# This list is to remove fields in a record.
|
19
|
+
# An example fields_removal_list = [%w[856 4 1], %w[041 _ _]].
|
20
|
+
# '_' means an empty indicator ''
|
21
|
+
# 3) How to use it:
|
22
|
+
# a. add/update subfields of existed fields in record: TindRecordUtil.update_record(record, tag_subfield_hash)
|
23
|
+
# b. remove a list of fields in the record: TindRecordUtil.update_record(record, nil, fields_removal_list)
|
24
|
+
# c. both a. and b. : TindRecordUtil.update_record(record, tag_subfield_hash, fields_removal_list)
|
25
|
+
def update_record(record, tag_subfield_hash, fields_removal_list = nil)
|
26
|
+
return record unless valid_hash?(tag_subfield_hash) || valid_hash?(fields_removal_list)
|
27
|
+
|
28
|
+
fields = record.fields
|
29
|
+
final_fields = tag_subfield_hash ? subfields_to_existed_fields(fields, tag_subfield_hash) : fields
|
30
|
+
remove_fields(final_fields, fields_removal_list) if fields_removal_list
|
31
|
+
new_record(final_fields)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def subfields_to_existed_fields(fields, tag_subfield_hash)
|
37
|
+
updated_fields = []
|
38
|
+
tags = tag_subfield_hash.keys
|
39
|
+
fields.each do |field|
|
40
|
+
tag = field.tag
|
41
|
+
need_change_subfield = tags.include? tag
|
42
|
+
updated_fields << (need_change_subfield ? field_changed_subfields(field, tag_subfield_hash[tag]) : field)
|
43
|
+
end
|
44
|
+
fields
|
45
|
+
end
|
46
|
+
|
47
|
+
# example: fields_removal_list = [%w[856 4 1]]
|
48
|
+
def remove_fields(fields, fields_removal_list)
|
49
|
+
fields.reject! { |f| field_in_removal_list?(f, fields_removal_list) }
|
50
|
+
end
|
51
|
+
|
52
|
+
def new_record(fields)
|
53
|
+
record = ::MARC::Record.new
|
54
|
+
fields.each { |f| record.append(f) }
|
55
|
+
record
|
56
|
+
end
|
57
|
+
|
58
|
+
# subfield_hash example { 'b' => 'subtitle', 'a' => 'title' }
|
59
|
+
def field_changed_subfields(field, subfield_hash)
|
60
|
+
tag = field.tag
|
61
|
+
indicators = [field.indicator1, field.indicator2]
|
62
|
+
subfields = changed_subfields(field, subfield_hash)
|
63
|
+
new_datafield(tag, indicators, subfields)
|
64
|
+
end
|
65
|
+
|
66
|
+
# example subfield_hash = { 'p' => 'subtitle'}
|
67
|
+
def changed_subfields(field, subfield_hash)
|
68
|
+
subfields = field.subfields
|
69
|
+
codes = subfields.map(&:code)
|
70
|
+
warning_duplicated_subfield_code(codes)
|
71
|
+
|
72
|
+
keys = subfield_hash.keys
|
73
|
+
|
74
|
+
keys_no_related_codes = keys - codes
|
75
|
+
keys_with_related_codes = keys - keys_no_related_codes
|
76
|
+
|
77
|
+
updated_subfields(subfields, keys_with_related_codes, subfield_hash)
|
78
|
+
|
79
|
+
subfields.concat new_subfields(field, keys_no_related_codes, subfield_hash)
|
80
|
+
subfields
|
81
|
+
end
|
82
|
+
|
83
|
+
# example subfield_hash = { 'p' => 'subtitle'}
|
84
|
+
def updated_subfields(subfields, existed_codes, subfield_hash)
|
85
|
+
subfields.each do |subfield|
|
86
|
+
code = subfield.code
|
87
|
+
next unless existed_codes.include? code
|
88
|
+
|
89
|
+
val = subfield_hash[code]
|
90
|
+
next unless val
|
91
|
+
|
92
|
+
subfield.value = val
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def new_subfields(_field, new_codes, subfield_hash)
|
97
|
+
subfields = []
|
98
|
+
subfield_hash.each do |key, val|
|
99
|
+
next unless val
|
100
|
+
|
101
|
+
subfields << ::MARC::Subfield.new(key, val) if new_codes.include? key
|
102
|
+
end
|
103
|
+
subfields
|
104
|
+
end
|
105
|
+
|
106
|
+
def field_in_removal_list?(f, fields_removal_list)
|
107
|
+
ls = [f.tag, clr(f.indicator1), clr(f.indicator2)]
|
108
|
+
fields_removal_list.include? ls
|
109
|
+
end
|
110
|
+
|
111
|
+
def clr(str)
|
112
|
+
str.strip.empty? ? '_' : str.strip
|
113
|
+
end
|
114
|
+
|
115
|
+
def new_datafield(tag, indicator, subfields)
|
116
|
+
datafield = ::MARC::DataField.new(tag, indicator[0], indicator[1])
|
117
|
+
subfields.each { |sf| datafield.append(sf) }
|
118
|
+
datafield
|
119
|
+
end
|
120
|
+
|
121
|
+
# suppose there are no duplicated subfield codes in a field
|
122
|
+
# giving warning for investigation if finding any dublicated subfields in a field
|
123
|
+
def warning_duplicated_subfield_code(codes)
|
124
|
+
duplicated_codes = codes.select { |code| codes.count(code) > 1 }.uniq
|
125
|
+
puts "Warning: duplicated subfields #{duplicated_codes.join(' ; ')}" unless duplicated_codes.empty?
|
126
|
+
end
|
127
|
+
|
128
|
+
def valid_hash?(hash)
|
129
|
+
hash && !hash.empty?
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require 'csv'
|
2
2
|
require 'marc'
|
3
|
+
require 'berkeley_library/tind/mapping/alma_base'
|
3
4
|
|
4
5
|
module BerkeleyLibrary
|
5
6
|
module TIND
|
6
7
|
module Mapping
|
7
8
|
module Util
|
9
|
+
include AlmaBase
|
8
10
|
|
9
11
|
class << self
|
10
12
|
|
@@ -78,6 +80,23 @@ module BerkeleyLibrary
|
|
78
80
|
all_from_xml(xml).first
|
79
81
|
end
|
80
82
|
|
83
|
+
def collection_config_correct?
|
84
|
+
no_including = BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags.empty?
|
85
|
+
no_excluding = BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags.empty?
|
86
|
+
no_including || no_excluding
|
87
|
+
end
|
88
|
+
|
89
|
+
# subfield util
|
90
|
+
def order_subfields(subfields, codes)
|
91
|
+
found_subfields = []
|
92
|
+
codes.each do |code|
|
93
|
+
sfs = subfields.select { |subfield| subfield.code == code }
|
94
|
+
found_subfields.concat sfs
|
95
|
+
end
|
96
|
+
not_found_subfields = subfields - found_subfields
|
97
|
+
found_subfields.concat not_found_subfields
|
98
|
+
end
|
99
|
+
|
81
100
|
private
|
82
101
|
|
83
102
|
def clr_row(row)
|
@@ -7,7 +7,7 @@ module BerkeleyLibrary
|
|
7
7
|
SUMMARY = 'TIND DA utilities for the UC Berkeley Library'.freeze
|
8
8
|
DESCRIPTION = 'UC Berkeley Library utility gem for working with the TIND DA digital archive.'.freeze
|
9
9
|
LICENSE = 'MIT'.freeze
|
10
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.7.0'.freeze
|
11
11
|
HOMEPAGE = 'https://github.com/BerkeleyLibrary/tind'.freeze
|
12
12
|
end
|
13
13
|
end
|
@@ -5,7 +5,7 @@ module BerkeleyLibrary
|
|
5
5
|
module Mapping
|
6
6
|
describe AlmaMultipleTIND do
|
7
7
|
let(:additona_245_field) { [Util.datafield('245', [' ', ' '], [Util.subfield('a', 'fake 245 a')])] }
|
8
|
-
let(:marc_obj) {
|
8
|
+
let(:marc_obj) { ::MARC::Record.new.append(additona_245_field) }
|
9
9
|
|
10
10
|
it ' get tind record' do
|
11
11
|
allow_any_instance_of(BerkeleyLibrary::TIND::Mapping::AlmaMultipleTIND).to receive(:alma_record_from).with('991085821143406532').and_return(marc_obj)
|
@@ -5,7 +5,7 @@ module BerkeleyLibrary
|
|
5
5
|
module Mapping
|
6
6
|
describe AlmaSingleTIND do
|
7
7
|
let(:additona_245_field) { [Util.datafield('245', [' ', ' '], [Util.subfield('a', 'fake 245 a')])] }
|
8
|
-
let(:marc_obj) {
|
8
|
+
let(:marc_obj) { ::MARC::Record.new.append(additona_245_field) }
|
9
9
|
|
10
10
|
before { BerkeleyLibrary::Alma::Config.default! }
|
11
11
|
after { BerkeleyLibrary::Alma::Config.send(:clear!) }
|
@@ -31,6 +31,11 @@ module BerkeleyLibrary
|
|
31
31
|
let(:pre_tag) { ['264', '264'] }
|
32
32
|
let(:pre_tag_subfield) { ['507'] }
|
33
33
|
|
34
|
+
after do
|
35
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = []
|
36
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = []
|
37
|
+
end
|
38
|
+
|
34
39
|
it 'excluding fast subject field' do
|
35
40
|
fields = qualified_alm_record.fields.select { |f| ['650', '245'].include? f.tag }
|
36
41
|
expect(fields.length).to eq 3
|
@@ -51,6 +56,49 @@ module BerkeleyLibrary
|
|
51
56
|
expect(group[:pre_tag_subfield].map(&:tag)).to eq pre_tag_subfield
|
52
57
|
end
|
53
58
|
|
59
|
+
context 'Defining list of fields mapping from Alma to TIND' do
|
60
|
+
it 'no including, excluding defined from config, return all Alma fields for mapping' do
|
61
|
+
selected_field_tags = %w[255 507 245 246 260 300]
|
62
|
+
fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
|
63
|
+
expect(fields_to_map(fields).map(&:tag)).to eq %w[255 507 245 246 260 300 300]
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'both including and excluding have tags, return empty: not allow to define both including and excluding at the same time' do
|
67
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = %w[254 650]
|
68
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[507 255 650 880]
|
69
|
+
|
70
|
+
selected_field_tags = %w[255 507 245 246 260 300]
|
71
|
+
fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
|
72
|
+
expect(fields_to_map(fields).map(&:tag)).to eq []
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'only including is defined: keeping fields defined in BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags' do
|
76
|
+
selected_field_tags = regular_field_tags
|
77
|
+
selected_field_tags << '880'
|
78
|
+
selected_field_tags << '001'
|
79
|
+
fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
|
80
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.including_origin_tags = %w[255 650]
|
81
|
+
expect(fields_to_map(fields).map(&:tag)).to eq %w[001 255 650 650 880] # return: Two 650 fields, one 880 field with subfield6 = '650'
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'only excluding origin tags are defined ' do
|
85
|
+
it 'excluding has 880, all 880 fields will be excluded.' do
|
86
|
+
selected_field_tags = %w[001 880 245 507 255 650 630 700 264]
|
87
|
+
fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
|
88
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[507 255 650 880]
|
89
|
+
final_field_tags = %w[001 245 630 700 264 264] # no 880 fields kept
|
90
|
+
expect(fields_to_map(fields).map(&:tag)).to eq final_field_tags
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'excluding has no 880, only 880 whose refered tag located in excluding list will be skipped ' do
|
94
|
+
selected_field_tags = %w[001 880 245 507 255 650 630 700 264]
|
95
|
+
fields = qualified_alm_record.fields.select { |f| selected_field_tags.include? f.tag }
|
96
|
+
BerkeleyLibrary::TIND::Mapping::AlmaBase.excluding_origin_tags = %w[507 255 650]
|
97
|
+
final_field_tags = %w[001 245 880 880 880 880 630 880 700 880 880 880 880 880 880 880 264 264]
|
98
|
+
expect(fields_to_map(fields).map(&:tag)).to eq final_field_tags
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
54
102
|
end
|
55
103
|
end
|
56
104
|
end
|
@@ -12,10 +12,9 @@ module BerkeleyLibrary
|
|
12
12
|
let(:tind_marc) { TindMarc.new(qualified_alm_record) }
|
13
13
|
|
14
14
|
let(:data_fields) { tind_marc.field_catalog.data_fields_880_group[:normal].concat tind_marc.field_catalog.data_fields_group[:normal] }
|
15
|
-
let(:no_880_matching_count) {
|
15
|
+
let(:no_880_matching_count) { 5 }
|
16
16
|
|
17
17
|
it 'get 880 un-matched fields' do
|
18
|
-
# puts tind_marc.send(:un_matched_fields_880, data_fields, '991032577079706532').inspect
|
19
18
|
expect(tind_marc.send(:un_matched_fields_880, data_fields, '991032577079706532').length).to eq no_880_matching_count
|
20
19
|
end
|
21
20
|
|
@@ -143,6 +143,23 @@ module BerkeleyLibrary
|
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
+
describe '9.1 - 710: subfields ordered on mapping file order' do
|
147
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('710'), false) }
|
148
|
+
it 'get subfield code ordered' do
|
149
|
+
codes = tindfield_from_single_map.to_datafield.subfields.map(&:code)
|
150
|
+
expect(codes).to eq %w[6 a e]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '9.2 subfield order - 255: subfields ordered on original subfields' do
|
155
|
+
let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('255'), false) }
|
156
|
+
|
157
|
+
it 'get subfield code ordered' do
|
158
|
+
codes = tindfield_from_single_map.to_datafield.subfields.map(&:code)
|
159
|
+
expect(codes).to eq %w[a c b 6]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
146
163
|
end
|
147
164
|
|
148
165
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'marc'
|
3
|
+
|
4
|
+
module BerkeleyLibrary
|
5
|
+
module TIND
|
6
|
+
module Mapping
|
7
|
+
describe TindRecordUtil do
|
8
|
+
let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
|
9
|
+
let(:qualified_alm_record) { qualified_alma_obj.record }
|
10
|
+
let(:tind_marc) { TindMarc.new(qualified_alm_record).tind_record }
|
11
|
+
|
12
|
+
it 'Remove fields from record' do
|
13
|
+
fields_removal_list = [%w[245 _ _], %w[700 1 _], %w[880 _ _]] # '_' means empty indicator
|
14
|
+
results = %w[255 246 260 300 300 490 630 650 710 903 041 269 255 880 880 880] # some 880's inicator is not empty
|
15
|
+
new_record = TindRecordUtil.update_record(tind_marc, nil, fields_removal_list)
|
16
|
+
expect(new_record.fields.map(&:tag)).to eq results
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'add/update sufields from record' do
|
20
|
+
tag_subfield_dic = { '245' => { 'b' => 'subtitle', 'a' => 'title', 'd' => 'fake' }, '255' => { 'a' => nil } }
|
21
|
+
new_record = TindRecordUtil.update_record(tind_marc, tag_subfield_dic, nil)
|
22
|
+
expect(new_record['245']['a']).to eq 'title'
|
23
|
+
expect(new_record['245']['b']).to eq 'subtitle'
|
24
|
+
expect(new_record['245']['d']).to eq 'fake'
|
25
|
+
expect(new_record['255']['a']).to eq 'fake_255_a'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"data": {
|
3
|
+
"url": "https://test_bucket.s3.amazonaws.com/",
|
4
|
+
"fields": {
|
5
|
+
"x-amz-algorithm": "AWS4-HMAC-SHA256",
|
6
|
+
"key": "711aca11-0de1-4110-ac73-8989",
|
7
|
+
"acl": "private",
|
8
|
+
"x-amz-signature": "ac8a1f0ed10e24a694fcaf266beca03687a20b46",
|
9
|
+
"x-amz-date": "20220729T204134Z",
|
10
|
+
"policy": "eyJjb25kaXRpbbs5r69kIjogInByaXZhdGUir5y1w9XQiOiAidGluZC10ZXN0YnVja2V0LWJl",
|
11
|
+
"x-amz-credential": "AKIA5NL2DYQQ3DIWY6Pe960bes66"
|
12
|
+
}
|
13
|
+
},
|
14
|
+
"bucket": "testbucket"
|
15
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
|
2
|
+
{
|
3
|
+
"code": 204,
|
4
|
+
"headers": {
|
5
|
+
"x_amz_id_2": "R8141+vOxVvEY7i8RuRTlLJE9DePeQ0hpZv0NYvSIvcO/e8OhrnO+Z3Yw=",
|
6
|
+
"x_amz_request_id": "H2EDK70DW0Y2D",
|
7
|
+
"date": "Fri, 29 Jul 2022 22:22:08 GMT",
|
8
|
+
"etag": "\"99914b932bd37a50b983c5e7c90ae93b\"",
|
9
|
+
"location": "https://testbucket.s3.amazonaws.com/b59a3d00-950e-45d2-af1c-746b8fde5977",
|
10
|
+
"server": "AmazonS3"
|
11
|
+
},
|
12
|
+
"body":""
|
13
|
+
}
|
@@ -50,6 +50,9 @@
|
|
50
50
|
</datafield> -->
|
51
51
|
<datafield ind1=" " ind2=" " tag="255">
|
52
52
|
<subfield code="a">fake_255_a</subfield>
|
53
|
+
<subfield code="c">fake_255_c</subfield>
|
54
|
+
<subfield code="b">fake_255_b</subfield>
|
55
|
+
<subfield code="6">fake_255_6</subfield>
|
53
56
|
</datafield>
|
54
57
|
|
55
58
|
<datafield ind1=" " ind2=" " tag="507">
|
@@ -165,14 +168,14 @@
|
|
165
168
|
<subfield code="e">xue.</subfield>
|
166
169
|
<subfield code="a">Sun, Xingyan,</subfield>
|
167
170
|
<subfield code="d">1753-1818,</subfield>
|
168
|
-
|
171
|
+
|
169
172
|
</datafield>
|
170
173
|
<datafield ind1="1" ind2=" " tag="880">
|
171
174
|
<subfield code="6">700-06/$1</subfield>
|
172
175
|
<subfield code="e">學.</subfield>
|
173
176
|
<subfield code="a">孫星衍,</subfield>
|
174
177
|
<subfield code="d">1753-1818,</subfield>
|
175
|
-
|
178
|
+
|
176
179
|
</datafield>
|
177
180
|
<datafield ind1="9" ind2=" " tag="710">
|
178
181
|
<subfield code="6">880-07</subfield>
|
@@ -260,4 +263,4 @@
|
|
260
263
|
<xb:exact>true</xb:exact>
|
261
264
|
<xb:responseDate>2022-01-27T19:08:03-0800</xb:responseDate>
|
262
265
|
</extraResponseData>
|
263
|
-
</searchRetrieveResponse>
|
266
|
+
</searchRetrieveResponse>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berkeley_library-tind
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Moles
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: berkeley_library-alma
|
@@ -65,6 +65,9 @@ dependencies:
|
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0.1'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 0.1.2
|
68
71
|
type: :runtime
|
69
72
|
prerelease: false
|
70
73
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,6 +75,9 @@ dependencies:
|
|
72
75
|
- - "~>"
|
73
76
|
- !ruby/object:Gem::Version
|
74
77
|
version: '0.1'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 0.1.2
|
75
81
|
- !ruby/object:Gem::Dependency
|
76
82
|
name: ice_nine
|
77
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -451,6 +457,7 @@ files:
|
|
451
457
|
- lib/berkeley_library/tind/mapping/tind_field_from_single_map.rb
|
452
458
|
- lib/berkeley_library/tind/mapping/tind_field_util.rb
|
453
459
|
- lib/berkeley_library/tind/mapping/tind_marc.rb
|
460
|
+
- lib/berkeley_library/tind/mapping/tind_record_util.rb
|
454
461
|
- lib/berkeley_library/tind/mapping/tind_subfield_util.rb
|
455
462
|
- lib/berkeley_library/tind/mapping/util.rb
|
456
463
|
- lib/berkeley_library/tind/marc.rb
|
@@ -458,7 +465,6 @@ files:
|
|
458
465
|
- lib/berkeley_library/tind/marc/xml_reader.rb
|
459
466
|
- lib/berkeley_library/tind/marc/xml_writer.rb
|
460
467
|
- lib/berkeley_library/tind/module_info.rb
|
461
|
-
- lib/berkeley_library/util/files.rb
|
462
468
|
- lib/berkeley_library/util/ods/spreadsheet.rb
|
463
469
|
- lib/berkeley_library/util/ods/xml/content_doc.rb
|
464
470
|
- lib/berkeley_library/util/ods/xml/document_node.rb
|
@@ -543,6 +549,7 @@ files:
|
|
543
549
|
- spec/berkeley_library/tind/mapping/tind_field_spec.rb
|
544
550
|
- spec/berkeley_library/tind/mapping/tind_field_util_spec.rb
|
545
551
|
- spec/berkeley_library/tind/mapping/tind_marc_spec.rb
|
552
|
+
- spec/berkeley_library/tind/mapping/tind_record_util_spec.rb
|
546
553
|
- spec/berkeley_library/tind/mapping/tind_subfield_util_spec.rb
|
547
554
|
- spec/berkeley_library/tind/mapping/util_spec.rb
|
548
555
|
- spec/berkeley_library/tind/marc/xml_reader_spec.rb
|
@@ -556,6 +563,10 @@ files:
|
|
556
563
|
- spec/berkeley_library/util/ods/xml/style/family_spec.rb
|
557
564
|
- spec/berkeley_library/util/ods/xml/table/table_row_spec.rb
|
558
565
|
- spec/berkeley_library/util/ods/xml/table/table_spec.rb
|
566
|
+
- spec/data/api/pre_assigned_response.json
|
567
|
+
- spec/data/api/result_file.csv
|
568
|
+
- spec/data/api/upload_file.json
|
569
|
+
- spec/data/api/upload_response.json
|
559
570
|
- spec/data/collection-names.txt
|
560
571
|
- spec/data/collections.json
|
561
572
|
- spec/data/disjoint-records.xml
|
@@ -605,83 +616,4 @@ rubygems_version: 3.1.6
|
|
605
616
|
signing_key:
|
606
617
|
specification_version: 4
|
607
618
|
summary: TIND DA utilities for the UC Berkeley Library
|
608
|
-
test_files:
|
609
|
-
- spec/.rubocop.yml
|
610
|
-
- spec/berkeley_library/tind/api/api_exception_spec.rb
|
611
|
-
- spec/berkeley_library/tind/api/api_spec.rb
|
612
|
-
- spec/berkeley_library/tind/api/collection_spec.rb
|
613
|
-
- spec/berkeley_library/tind/api/date_range_spec.rb
|
614
|
-
- spec/berkeley_library/tind/api/format_spec.rb
|
615
|
-
- spec/berkeley_library/tind/api/search_spec.rb
|
616
|
-
- spec/berkeley_library/tind/config_spec.rb
|
617
|
-
- spec/berkeley_library/tind/export/column_group_spec.rb
|
618
|
-
- spec/berkeley_library/tind/export/column_spec.rb
|
619
|
-
- spec/berkeley_library/tind/export/config_spec.rb
|
620
|
-
- spec/berkeley_library/tind/export/export_command_spec.rb
|
621
|
-
- spec/berkeley_library/tind/export/export_format_spec.rb
|
622
|
-
- spec/berkeley_library/tind/export/export_matcher.rb
|
623
|
-
- spec/berkeley_library/tind/export/export_spec.rb
|
624
|
-
- spec/berkeley_library/tind/export/exporter_spec.rb
|
625
|
-
- spec/berkeley_library/tind/export/row_spec.rb
|
626
|
-
- spec/berkeley_library/tind/export/table_spec.rb
|
627
|
-
- spec/berkeley_library/tind/mapping/additional_datafield_process_spec.rb
|
628
|
-
- spec/berkeley_library/tind/mapping/alma_base_spec.rb
|
629
|
-
- spec/berkeley_library/tind/mapping/alma_multiple_tind_spec.rb
|
630
|
-
- spec/berkeley_library/tind/mapping/alma_single_tind_spec.rb
|
631
|
-
- spec/berkeley_library/tind/mapping/alma_spec.rb
|
632
|
-
- spec/berkeley_library/tind/mapping/config_spec.rb
|
633
|
-
- spec/berkeley_library/tind/mapping/csv_mapper_spec.rb
|
634
|
-
- spec/berkeley_library/tind/mapping/csv_multiple_mapper_spec.rb
|
635
|
-
- spec/berkeley_library/tind/mapping/external_tind_field_spec.rb
|
636
|
-
- spec/berkeley_library/tind/mapping/field_catalog_spec.rb
|
637
|
-
- spec/berkeley_library/tind/mapping/field_catalog_util_spec.rb
|
638
|
-
- spec/berkeley_library/tind/mapping/match_tind_field_spec.rb
|
639
|
-
- spec/berkeley_library/tind/mapping/misc_spec.rb
|
640
|
-
- spec/berkeley_library/tind/mapping/multiple_rule_spec.rb
|
641
|
-
- spec/berkeley_library/tind/mapping/single_rule_spec.rb
|
642
|
-
- spec/berkeley_library/tind/mapping/tind_control_subfield_spec.rb
|
643
|
-
- spec/berkeley_library/tind/mapping/tind_field_from_leader_spec.rb
|
644
|
-
- spec/berkeley_library/tind/mapping/tind_field_from_multiple_map_spec.rb
|
645
|
-
- spec/berkeley_library/tind/mapping/tind_field_from_single_map_spec.rb
|
646
|
-
- spec/berkeley_library/tind/mapping/tind_field_spec.rb
|
647
|
-
- spec/berkeley_library/tind/mapping/tind_field_util_spec.rb
|
648
|
-
- spec/berkeley_library/tind/mapping/tind_marc_spec.rb
|
649
|
-
- spec/berkeley_library/tind/mapping/tind_subfield_util_spec.rb
|
650
|
-
- spec/berkeley_library/tind/mapping/util_spec.rb
|
651
|
-
- spec/berkeley_library/tind/marc/xml_reader_spec.rb
|
652
|
-
- spec/berkeley_library/tind/marc/xml_writer_spec.rb
|
653
|
-
- spec/berkeley_library/util/ods/spreadsheet_spec.rb
|
654
|
-
- spec/berkeley_library/util/ods/xml/content_doc_spec.rb
|
655
|
-
- spec/berkeley_library/util/ods/xml/manifest/file_entry_spec.rb
|
656
|
-
- spec/berkeley_library/util/ods/xml/manifest/manifest_spec.rb
|
657
|
-
- spec/berkeley_library/util/ods/xml/office/document_content_spec.rb
|
658
|
-
- spec/berkeley_library/util/ods/xml/style/automatic_styles_spec.rb
|
659
|
-
- spec/berkeley_library/util/ods/xml/style/family_spec.rb
|
660
|
-
- spec/berkeley_library/util/ods/xml/table/table_row_spec.rb
|
661
|
-
- spec/berkeley_library/util/ods/xml/table/table_spec.rb
|
662
|
-
- spec/data/collection-names.txt
|
663
|
-
- spec/data/collections.json
|
664
|
-
- spec/data/disjoint-records.xml
|
665
|
-
- spec/data/issue-4.xml
|
666
|
-
- spec/data/mapping/991032333019706532-sru.xml
|
667
|
-
- spec/data/mapping/one_to_multiple_mapping.csv
|
668
|
-
- spec/data/mapping/one_to_one_mapping.csv
|
669
|
-
- spec/data/mapping/record.xml
|
670
|
-
- spec/data/mapping/record_not_qualified.xml
|
671
|
-
- spec/data/new-records.xml
|
672
|
-
- spec/data/record-184453.xml
|
673
|
-
- spec/data/record-184458.xml
|
674
|
-
- spec/data/record-187888.xml
|
675
|
-
- spec/data/records-api-search-cjk-p1.xml
|
676
|
-
- spec/data/records-api-search-cjk-p2.xml
|
677
|
-
- spec/data/records-api-search-p1.xml
|
678
|
-
- spec/data/records-api-search-p2.xml
|
679
|
-
- spec/data/records-api-search-p3.xml
|
680
|
-
- spec/data/records-api-search-p4.xml
|
681
|
-
- spec/data/records-api-search-p5.xml
|
682
|
-
- spec/data/records-api-search-p6.xml
|
683
|
-
- spec/data/records-api-search-p7.xml
|
684
|
-
- spec/data/records-api-search.xml
|
685
|
-
- spec/data/records-manual-search.xml
|
686
|
-
- spec/spec_helper.rb
|
687
|
-
- test/profile/table_from_records_profile.rb
|
619
|
+
test_files: []
|
@@ -1,38 +0,0 @@
|
|
1
|
-
module BerkeleyLibrary
|
2
|
-
module Util
|
3
|
-
# TODO: Move this to `berkeley_library-util`
|
4
|
-
module Files
|
5
|
-
class << self
|
6
|
-
include Files
|
7
|
-
end
|
8
|
-
|
9
|
-
def file_exists?(path)
|
10
|
-
(path.respond_to?(:exist?) && path.exist?) ||
|
11
|
-
(path.respond_to?(:to_str) && File.exist?(path))
|
12
|
-
end
|
13
|
-
|
14
|
-
def parent_exists?(path)
|
15
|
-
path.respond_to?(:parent) && path.parent.exist? ||
|
16
|
-
path.respond_to?(:to_str) && Pathname.new(path).parent.exist?
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns true if `obj` is close enough to an IO object for Nokogiri
|
20
|
-
# to parse as one.
|
21
|
-
#
|
22
|
-
# @param obj [Object] the object that might be an IO
|
23
|
-
# @see https://github.com/sparklemotion/nokogiri/blob/v1.11.1/lib/nokogiri/xml/sax/parser.rb#L81 Nokogiri::XML::SAX::Parser#parse
|
24
|
-
def reader_like?(obj)
|
25
|
-
obj.respond_to?(:read) && obj.respond_to?(:close)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns true if `obj` is close enough to an IO object for Nokogiri
|
29
|
-
# to write to.
|
30
|
-
#
|
31
|
-
# @param obj [Object] the object that might be an IO
|
32
|
-
def writer_like?(obj)
|
33
|
-
obj.respond_to?(:write) && obj.respond_to?(:close)
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|