berkeley_library-tind 0.5.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +15 -3
  3. data/.gitignore +3 -0
  4. data/.idea/inspectionProfiles/Project_Default.xml +10 -0
  5. data/.idea/tind.iml +10 -9
  6. data/.rubocop.yml +1 -1
  7. data/CHANGES.md +15 -1
  8. data/README.md +165 -2
  9. data/berkeley_library-tind.gemspec +2 -2
  10. data/bin/alma-multiple-tind +50 -0
  11. data/bin/alma-single-tind +48 -0
  12. data/bin/save_tind_records +80 -0
  13. data/bin/tind-marc +73 -0
  14. data/lib/berkeley_library/tind/export/ods_exporter.rb +4 -6
  15. data/lib/berkeley_library/tind/mapping/additional_datafield_process.rb +128 -0
  16. data/lib/berkeley_library/tind/mapping/alma.rb +42 -0
  17. data/lib/berkeley_library/tind/mapping/alma_base.rb +108 -0
  18. data/lib/berkeley_library/tind/mapping/alma_multiple_tind.rb +31 -0
  19. data/lib/berkeley_library/tind/mapping/alma_single_tind.rb +28 -0
  20. data/lib/berkeley_library/tind/mapping/config.rb +44 -0
  21. data/lib/berkeley_library/tind/mapping/csv_mapper.rb +35 -0
  22. data/lib/berkeley_library/tind/mapping/csv_multiple_mapper.rb +41 -0
  23. data/lib/berkeley_library/tind/mapping/data/one_to_multiple_mapping.csv +4 -0
  24. data/lib/berkeley_library/tind/mapping/data/one_to_one_mapping.csv +39 -0
  25. data/lib/berkeley_library/tind/mapping/external_tind_field.rb +103 -0
  26. data/lib/berkeley_library/tind/mapping/field_catalog.rb +137 -0
  27. data/lib/berkeley_library/tind/mapping/field_catalog_util.rb +105 -0
  28. data/lib/berkeley_library/tind/mapping/match_tind_field.rb +77 -0
  29. data/lib/berkeley_library/tind/mapping/misc.rb +69 -0
  30. data/lib/berkeley_library/tind/mapping/multiple_rule.rb +36 -0
  31. data/lib/berkeley_library/tind/mapping/single_rule.rb +149 -0
  32. data/lib/berkeley_library/tind/mapping/tind_control_subfield.rb +59 -0
  33. data/lib/berkeley_library/tind/mapping/tind_field.rb +49 -0
  34. data/lib/berkeley_library/tind/mapping/tind_field_from_leader.rb +27 -0
  35. data/lib/berkeley_library/tind/mapping/tind_field_from_multiple_map.rb +59 -0
  36. data/lib/berkeley_library/tind/mapping/tind_field_from_single_map.rb +182 -0
  37. data/lib/berkeley_library/tind/mapping/tind_field_util.rb +112 -0
  38. data/lib/berkeley_library/tind/mapping/tind_marc.rb +134 -0
  39. data/lib/berkeley_library/tind/mapping/tind_record_util.rb +135 -0
  40. data/lib/berkeley_library/tind/mapping/tind_subfield_util.rb +154 -0
  41. data/lib/berkeley_library/tind/mapping/util.rb +136 -0
  42. data/lib/berkeley_library/tind/mapping.rb +1 -0
  43. data/lib/berkeley_library/tind/module_info.rb +1 -1
  44. data/spec/berkeley_library/tind/mapping/additional_datafield_process_spec.rb +35 -0
  45. data/spec/berkeley_library/tind/mapping/alma_base_spec.rb +115 -0
  46. data/spec/berkeley_library/tind/mapping/alma_multiple_tind_spec.rb +20 -0
  47. data/spec/berkeley_library/tind/mapping/alma_single_tind_spec.rb +87 -0
  48. data/spec/berkeley_library/tind/mapping/alma_spec.rb +28 -0
  49. data/spec/berkeley_library/tind/mapping/config_spec.rb +19 -0
  50. data/spec/berkeley_library/tind/mapping/csv_mapper_spec.rb +27 -0
  51. data/spec/berkeley_library/tind/mapping/csv_multiple_mapper_spec.rb +27 -0
  52. data/spec/berkeley_library/tind/mapping/external_tind_field_spec.rb +45 -0
  53. data/spec/berkeley_library/tind/mapping/field_catalog_spec.rb +78 -0
  54. data/spec/berkeley_library/tind/mapping/field_catalog_util_spec.rb +105 -0
  55. data/spec/berkeley_library/tind/mapping/match_tind_field_spec.rb +24 -0
  56. data/spec/berkeley_library/tind/mapping/misc_spec.rb +51 -0
  57. data/spec/berkeley_library/tind/mapping/multiple_rule_spec.rb +44 -0
  58. data/spec/berkeley_library/tind/mapping/single_rule_spec.rb +52 -0
  59. data/spec/berkeley_library/tind/mapping/tind_control_subfield_spec.rb +96 -0
  60. data/spec/berkeley_library/tind/mapping/tind_field_from_leader_spec.rb +21 -0
  61. data/spec/berkeley_library/tind/mapping/tind_field_from_multiple_map_spec.rb +31 -0
  62. data/spec/berkeley_library/tind/mapping/tind_field_from_single_map_spec.rb +167 -0
  63. data/spec/berkeley_library/tind/mapping/tind_field_spec.rb +60 -0
  64. data/spec/berkeley_library/tind/mapping/tind_field_util_spec.rb +68 -0
  65. data/spec/berkeley_library/tind/mapping/tind_marc_spec.rb +88 -0
  66. data/spec/berkeley_library/tind/mapping/tind_record_util_spec.rb +30 -0
  67. data/spec/berkeley_library/tind/mapping/tind_subfield_util_spec.rb +48 -0
  68. data/spec/berkeley_library/tind/mapping/util_spec.rb +56 -0
  69. data/spec/berkeley_library/tind/marc/xml_writer_spec.rb +24 -0
  70. data/spec/data/api/pre_assigned_response.json +15 -0
  71. data/spec/data/api/result_file.csv +3 -0
  72. data/spec/data/api/upload_file.json +1 -0
  73. data/spec/data/api/upload_response.json +13 -0
  74. data/spec/data/mapping/991032333019706532-sru.xml +216 -0
  75. data/spec/data/mapping/one_to_multiple_mapping.csv +4 -0
  76. data/spec/data/mapping/one_to_one_mapping.csv +39 -0
  77. data/spec/data/mapping/record.xml +266 -0
  78. data/spec/data/mapping/record_not_qualified.xml +36 -0
  79. metadata +89 -54
  80. data/lib/berkeley_library/util/files.rb +0 -39
@@ -0,0 +1,167 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe TindFieldFromSingleMap do
8
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
9
+ let(:qualified_alm_record) { qualified_alma_obj.record }
10
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('245'), false) }
11
+
12
+ # 1. Subfield one to one mapping
13
+ # 2. Subfield not listed in csv file is not mapped
14
+ describe '1. subfield one to one mapping' do
15
+ it 'get tindfield tag: 245 => 245 ' do
16
+ expect(tindfield_from_single_map.to_datafield.tag).to eq '245'
17
+ end
18
+
19
+ it 'get 245$a' do
20
+ expect(tindfield_from_single_map.to_datafield['a']).to eq 'Cang jie pian :'
21
+ end
22
+
23
+ it 'get 245$b' do
24
+ expect(tindfield_from_single_map.to_datafield['b']).to eq '[san juan] /'
25
+ end
26
+
27
+ it 'get 245$6' do
28
+ expect(tindfield_from_single_map.to_datafield['6']).to eq '880-99'
29
+ end
30
+
31
+ it 'shoud not get 245$c' do
32
+ expect(tindfield_from_single_map.to_datafield['c']).to eq nil
33
+ end
34
+ end
35
+ describe '2. mapping indicators' do
36
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('710'), false) }
37
+
38
+ it 'get indicator1' do
39
+ expect(tindfield_from_single_map.to_datafield.indicator1).to eq '2'
40
+ end
41
+
42
+ it 'get indicator2' do
43
+ expect(tindfield_from_single_map.to_datafield.indicator2).to eq ' '
44
+ end
45
+
46
+ end
47
+
48
+ # 264 datafield mapping defined in csv has only one mapping occurrence
49
+ # To test only the first occurrence is mapped
50
+ describe '3. multiple origin 264 fields => only mapping the first occurrence' do
51
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('264'), false) }
52
+
53
+ it 'get tindfield tag: 264 => 260' do
54
+ expect(tindfield_from_single_map.to_datafield.tag).to eq '260'
55
+ end
56
+
57
+ it 'get the first 264$a' do
58
+ expect(tindfield_from_single_map.to_datafield['a']).to eq '264 fake a 1'
59
+ end
60
+
61
+ it 'get the first 264$b' do
62
+ expect(tindfield_from_single_map.to_datafield['b']).to eq '264 fake b 1'
63
+ end
64
+
65
+ it 'get the first 264$c' do
66
+ expect(tindfield_from_single_map.to_datafield['c']).to eq '264 fake c 1'
67
+ end
68
+ end
69
+
70
+ # 1. 507 datafield has pre-existed subfield a defined in csv file
71
+ # 2. To test excluding subfield a mapping from 507
72
+ # 3. TindFieldFromSingleMap.new(): input excluding_subfield = true
73
+ describe '4. pre_existed subfield = true' do
74
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('507'), true) }
75
+
76
+ it 'get tindfield tag: 507 => 255 ' do
77
+ expect(tindfield_from_single_map.to_datafield.tag).to eq '255'
78
+ end
79
+
80
+ it 'pre_existed 507$a is not mapped' do
81
+ expect(tindfield_from_single_map.to_datafield['a']).to eq nil
82
+ end
83
+ end
84
+
85
+ # To test rule: subfield value combined without concatenation symbol defined in csv
86
+ describe '5. subfields are combined' do
87
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('246'), false) }
88
+
89
+ it 'get tindfield tag: 246 => 246' do
90
+ expect(tindfield_from_single_map.to_datafield.tag).to eq '246'
91
+ end
92
+
93
+ it 'get combined subfield a, b, p, n' do
94
+ expect(tindfield_from_single_map.to_datafield['a']).to eq 'Sun shi Cang jie pian ^^ b fake ^^ p fake ^^ n fake'
95
+ end
96
+
97
+ end
98
+
99
+ # To test multiple rules mapped to the same tinddatafield
100
+ describe '6. subfields are combined with multiple rules' do
101
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field('630'), false) }
102
+ let(:combined_value) { 'fake a * fake b * fake c * fake d * fake f * fake j * fake k * fake l * fake m * fake n * fake o * fake p * fake q * fake r * fake s * fake t * fake x1 -- fake x2 ' }
103
+
104
+ it 'get tindfield tag: 630 => 630' do
105
+ expect(tindfield_from_single_map.to_datafield.tag).to eq '630'
106
+ end
107
+
108
+ it 'get combined subfield a, b, p, n' do
109
+ expect(tindfield_from_single_map.to_datafield['a']).to eq combined_value
110
+ end
111
+
112
+ end
113
+
114
+ # 1. To test 880 datafield
115
+ # 2. 880 tag reversed
116
+ # 3. subfields z,y, z combined with concatenation symbol defined in csv file
117
+ describe '7. 880 datafield mapping' do
118
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field_880('650-05/$1'), false) }
119
+
120
+ it 'get tindfield tag: 880 => 880' do
121
+ expect(tindfield_from_single_map.to_datafield.tag).to eq '880'
122
+ end
123
+
124
+ it 'get 880$a: subfield a x,y,z combined to subfield a with symbol " -- " ' do
125
+ expect(tindfield_from_single_map.to_datafield['a']).to eq '經部 小學類 -- 字書. '
126
+ end
127
+
128
+ end
129
+
130
+ # 1. To test 880 datafield
131
+ # 2. Tag in 880 subfield 6 is mapped based on a regular datafield mapping rule
132
+ # 3. 880 datafield with 507 tag in subfield 6
133
+ # mapped from 507-09/$1 to 255-09/$1
134
+ describe '8. 880 subfield 6 value mapped to new destination tag' do
135
+ let(:tindfield_from_single_map) { TindFieldFromSingleMap.new(qualified_alma_obj.field_880('507-09/$1'), false) }
136
+
137
+ it 'get tindfield tag: 880 => 880' do
138
+ expect(tindfield_from_single_map.to_datafield.tag).to eq '880'
139
+ end
140
+
141
+ it 'get subfield 6: "507-09/$1" => "255-09/$1" ' do
142
+ expect(tindfield_from_single_map.to_datafield['6']).to eq '255-09/$1'
143
+ end
144
+ end
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
+
163
+ end
164
+
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe TindField do
8
+ it 'Field 035' do
9
+ f = TindField.f_035('Alibaba123')
10
+ expect(f.tag).to eq '035'
11
+ expect(f['a']).to eq 'Alibaba123'
12
+ end
13
+
14
+ it 'Field 035 derived from mms_id' do
15
+ f = TindField.f_035_from_alma_id('991085821143406532', 'cu_news')
16
+ expect(f.tag).to eq '035'
17
+ expect(f['a']).to eq '(cu_news)991085821143406532'
18
+ end
19
+
20
+ it 'Field 245$p' do
21
+ f = TindField.f_245_p('fake_title_version')
22
+ expect(f.tag).to eq '245'
23
+ expect(f['p']).to eq 'fake_title_version'
24
+ end
25
+
26
+ it 'Field FFT' do
27
+ f = TindField.f_fft('http://host/image.tif', 'news')
28
+ expect(f.tag).to eq 'FFT'
29
+ expect(f['a']).to eq 'http://host/image.tif'
30
+ expect(f['d']).to eq 'news'
31
+ end
32
+
33
+ it 'Field 902$d' do
34
+ f = TindField.f_902_d
35
+ puts f['d']
36
+ expect(f.tag).to eq '902'
37
+ expect(f['d']).to match(/^\d{4}-\d{2}-\d{2}$/)
38
+ end
39
+
40
+ it 'Field 902$n' do
41
+ f = TindField.f_902_n('YZ')
42
+ expect(f.tag).to eq '902'
43
+ expect(f['n']).to eq 'YZ'
44
+ end
45
+
46
+ it 'Field 982$p' do
47
+ f = TindField.f_982_p('project name')
48
+ expect(f.tag).to eq '982'
49
+ expect(f['p']).to eq 'project name'
50
+ end
51
+
52
+ it 'Marc field' do
53
+ f = TindField.f('998', 'g', 'file name')
54
+ expect(f.tag).to eq '998'
55
+ expect(f['g']).to eq 'file name'
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe TindFieldUtil do
8
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
9
+ let(:qualified_alm_record) { qualified_alma_obj.record }
10
+
11
+ let(:tind_marc) { TindMarc.new(qualified_alm_record) }
12
+
13
+ let(:normal_fields_group) { tind_marc.field_catalog.data_fields_group[:normal] }
14
+ let(:field_normal) { qualified_alma_obj.field('245') }
15
+ let(:field_pre_existed_field) { qualified_alma_obj.field('264') } # 264 has pre_existed field defined in csv file
16
+ let(:field_pre_existed_field_and_subfield) { qualified_alma_obj.field('507') } # 507 has pre_existed_field_subfield defined in csv file
17
+ let(:fields_880_group) { tind_marc.field_catalog.data_fields_880_group[:normal] }
18
+ let(:field_880_245) { qualified_alma_obj.field_880('245-01/$1') }
19
+
20
+ it 'get a rule on datafield' do
21
+ expect(tind_marc.rule(field_normal)).to be_an_instance_of BerkeleyLibrary::TIND::Mapping::SingleRule
22
+ end
23
+
24
+ it 'tindfield found existing list of tindfields' do
25
+ expect(tind_marc.tindfield_existed?(field_pre_existed_field, normal_fields_group)).to eq true
26
+ end
27
+
28
+ it 'tindfield not found existing list of tindfields' do
29
+ expect(tind_marc.tindfield_existed?(field_normal, normal_fields_group)).to eq false
30
+ end
31
+
32
+ # fake 255$a existing in the record.xml
33
+ it 'tindfield subfield found in existing list of tindfields' do
34
+ expect(tind_marc.tindfield_subfield_existed?(field_pre_existed_field_and_subfield, normal_fields_group)).to eq true
35
+ end
36
+
37
+ it 'tindfield subfield not found existing list of tindfields' do
38
+ expect(tind_marc.tindfield_subfield_existed?(field_normal, normal_fields_group)).to eq false
39
+ end
40
+
41
+ it 'find an 880 field, subfield6 including tag 245' do
42
+ expect(tind_marc.field_880_on_subfield6_tag('245', fields_880_group)['6']).to eq '245-01/$1'
43
+ end
44
+
45
+ describe '# field_pre_existed' do
46
+ it 'find pre_existed 880 field' do
47
+ expect(tind_marc.send(:field_pre_existed, '245', field_880_245, fields_880_group)['6']).to eq '245-01/$1'
48
+ end
49
+
50
+ it 'find no pre_existed 880 field' do
51
+ expect(tind_marc.send(:field_pre_existed, '247', field_880_245, fields_880_group)).to eq nil
52
+ end
53
+
54
+ it 'find pre_existed regular field' do
55
+ expect(tind_marc.send(:field_pre_existed, '245', field_normal, normal_fields_group).tag).to eq '245'
56
+ end
57
+
58
+ it 'find no pre_existed regular field' do
59
+ expect(tind_marc.send(:field_pre_existed, '299', field_normal, normal_fields_group)).to eq nil
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe TindMarc do
8
+
9
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
10
+ let(:qualified_alm_record) { qualified_alma_obj.record }
11
+
12
+ let(:tind_marc) { TindMarc.new(qualified_alm_record) }
13
+
14
+ let(:normal_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('507')] }
15
+ let(:normal_tindfield_tags) { ['245', '255'] }
16
+
17
+ let(:with_pre_existed_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('264')] }
18
+ let(:current_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('260')] }
19
+ let(:with_pre_existed_tind_fields_tags) { ['245'] }
20
+
21
+ let(:with_pre_existed_subfield_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('507')] }
22
+ let(:current_with_pre_existed_subfield_fields) { [qualified_alma_obj.field('245'), qualified_alma_obj.field('255')] }
23
+ let(:with_pre_existed_tind_subfield_fields_tags) { ['245'] }
24
+
25
+ # mapped on pre_existed_field rule: "260"
26
+ # mapped on pre_existed_subfield rule: "255"
27
+ let(:tindfield_tags) do
28
+ %w[255 245 246 260 300 300 490 630 650
29
+ 700 710 903 041 269 255]
30
+ end
31
+
32
+ let(:tind_880_subfield6_tags) { ['245', '246', '260', '490', '650', '700', '710', '255', nil, '500', '500', '500', '500'] }
33
+
34
+ # mapped on pre_existed_field rule => ''
35
+ # mapped on pre_existed_subfield rule: "880-255-09"
36
+ # 880 datafields with '00' in subfield 6 come from field_catalog - 4 tindfields
37
+ let(:tindfield_880_normal_tags) do
38
+ %w[880-245-01 880-246-02 880-260-03 880-490-04 880-650-05
39
+ 880-700-06 880-710-07 880-255-09
40
+ 880-500-00 880-500-00 880-500-00 880-500-00]
41
+ end
42
+
43
+ context '# From public methods: ' do
44
+ it 'get a TIND record' do
45
+ expect(tind_marc.tind_record).to be_a ::MARC::Record
46
+ end
47
+
48
+ it 'get all tindfields' do
49
+ expect(tind_marc.tindfields.count).to eq 28 # 7 (normal tindfields) + 21 (880 tindfields)
50
+ end
51
+ end
52
+
53
+ context '# From private methods: ' do
54
+
55
+ it 'get normal tindfield tags' do
56
+ expect(tind_marc.send(:tindfields_group).map(&:tag)).to eq tindfield_tags
57
+ end
58
+
59
+ it 'get 880 tindfield tags' do
60
+ expect(tind_marc.send(:tindfields_group_880).map { |f| tind_marc.origin_mapping_tag(f) }).to eq tind_880_subfield6_tags
61
+ end
62
+
63
+ it 'get 880 tindfield subfield6 values' do
64
+ expect(tind_marc.fields_880_subfield6(tind_marc.send(:tindfields_group_880))).to eq tindfield_880_normal_tags
65
+ end
66
+
67
+ it 'get normal tindfields' do
68
+ expect(tind_marc.send(:tindfields_from_normal, normal_fields).map(&:tag)).to eq normal_tindfield_tags
69
+ end
70
+
71
+ it 'get control tindfields' do
72
+ expect(tind_marc.send(:tindfields_from_control, []).map(&:tag)).to eq ['041', '269']
73
+ end
74
+
75
+ it 'get tindfields with pre_existed field' do
76
+ expect(tind_marc.send(:tindfields_with_pre_existed_field, with_pre_existed_fields, current_fields).map(&:tag)).to eq with_pre_existed_tind_fields_tags
77
+ end
78
+
79
+ it 'get tindfields with pre_existed_subfield' do
80
+ expect(tind_marc.send(:tindfields_with_pre_existed_subfield, with_pre_existed_subfield_fields, current_with_pre_existed_subfield_fields).map(&:tag)).to eq normal_tindfield_tags
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+ end
87
+ end
88
+ 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,48 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe TindSubfieldUtil do
8
+
9
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
10
+ let(:qualified_alm_record) { qualified_alma_obj.record }
11
+
12
+ let(:tind_marc) { TindMarc.new(qualified_alm_record) }
13
+
14
+ let(:data_fields) { tind_marc.field_catalog.data_fields_880_group[:normal].concat tind_marc.field_catalog.data_fields_group[:normal] }
15
+ let(:regular_field_with_subfield6) { qualified_alma_obj.field('246') }
16
+ let(:regular_field_without_subfield6) { qualified_alma_obj.field('300') }
17
+ let(:field_880_with_subfield6) { qualified_alma_obj.field_880('490-04/$1') }
18
+ let(:field_880_without_subfield6) { qualified_alma_obj.field_880(nil) }
19
+ let(:no_880_matching_list) { ['No matching: 880 $ 245-01/$1 ', 'No matching: 245 $ 880-99 ', 'No matching: 630 $ 880-16 '] }
20
+ let(:subfield6_values) { ['245-01/$1', '880-16', '246-02/$04', '880-02'] }
21
+
22
+ it 'get origin tag from regular field' do
23
+ expect(tind_marc.origin_mapping_tag(regular_field_with_subfield6)).to eq '246'
24
+ end
25
+
26
+ it 'get clean value' do
27
+ str = 'to [test] removing : special characters :;/'
28
+ expect(tind_marc.send(:clr_value, str)).to eq 'to test removing : special characters'
29
+ end
30
+
31
+ it 'get the lowest seq no' do
32
+ expect(tind_marc.send(:subfield6_value_with_lowest_seq_no, subfield6_values)).to eq '245-01/$1'
33
+ end
34
+
35
+ context 'get origin tag from a 880 field' do
36
+ it 'with subfield6' do
37
+ expect(tind_marc.origin_mapping_tag(field_880_with_subfield6)).to eq '490'
38
+ end
39
+
40
+ it 'without subfield6' do
41
+ expect(tind_marc.origin_mapping_tag(field_880_without_subfield6)).to eq nil
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'marc'
3
+
4
+ module BerkeleyLibrary
5
+ module TIND
6
+ module Mapping
7
+ describe Util do
8
+
9
+ let(:qualified_alma_obj) { Alma.new('spec/data/mapping/record.xml') }
10
+ let(:qualified_alm_record) { qualified_alma_obj.record }
11
+
12
+ let(:un_qualified_alma_obj) { Alma.new('spec/data/mapping/record_not_qualified.xml') }
13
+ let(:un_qualified_alm_record) { un_qualified_alma_obj.record }
14
+
15
+ let(:field) { qualified_alma_obj.field('260') }
16
+ let(:subfield_hash) do
17
+ { '6' => '880-03',
18
+ 'a' => '[Daliang] :',
19
+ 'b' => 'Daliang fu shu,',
20
+ 'c' => 'Qing Qianlong 50 nian [1785]' }
21
+ end
22
+
23
+ it 'get three digits' do
24
+ tag = '1'
25
+ expect(Util.send(:format_tag, tag)).to eq '001'
26
+ end
27
+
28
+ it 'get letters' do
29
+ tag = 'LDR'
30
+ expect(Util.send(:format_tag, tag)).to eq 'LDR'
31
+ end
32
+
33
+ it 'get subfield hash from a field' do
34
+ expect(Util.subfield_hash(field)).to eq subfield_hash
35
+ end
36
+
37
+ it 'get qualified alma record' do
38
+ expect(Util.qualified_alma_record?(qualified_alm_record)).to eq true
39
+ end
40
+
41
+ it 'get unqualified alma record' do
42
+ expect(Util.qualified_alma_record?(un_qualified_alm_record)).to eq false
43
+ end
44
+
45
+ it 'get symbol from string "a--a"' do
46
+ expect(Util.concatenation_symbol('a--a')).to eq ' -- '
47
+ end
48
+
49
+ it 'get symbol from nil' do
50
+ expect(Util.concatenation_symbol(nil)).to eq ' '
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
@@ -187,6 +187,30 @@ module BerkeleyLibrary
187
187
  end
188
188
  end
189
189
  end
190
+
191
+ it 'writes to a Tempfile object' do
192
+ Dir.mktmpdir(File.basename(__FILE__, '.rb')) do |dir|
193
+ out = Tempfile.new(File.join(dir, 'marc.xml'))
194
+ begin
195
+ # noinspection RubyMismatchedArgumentType
196
+ w = XMLWriter.new(out)
197
+ w.write(record)
198
+ w.close
199
+
200
+ expected = File.open(input_path) { |f| Nokogiri::XML(f) }
201
+ actual = File.open(out.path) { |f| Nokogiri::XML(f) }
202
+ ensure
203
+ out.close
204
+ out.unlink
205
+ end
206
+
207
+ aggregate_failures do
208
+ EquivalentXml.equivalent?(expected, actual) do |n1, n2, result|
209
+ expect(n2.to_s).to eq(n1.to_s) unless result
210
+ end
211
+ end
212
+ end
213
+ end
190
214
  end
191
215
  end
192
216
  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,3 @@
1
+ mmsid,filename,object_key,etag,md5,timestamp
2
+ 99100123,a.jpg,a123b123a,b698k56a,matched,06/12/2022
3
+ 99100123,b.jpg,a123b123b,b698k54b,matched,06/12/2022
@@ -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
+ }