hydra-pbcore 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/.gitignore +1 -0
  2. data/Rakefile +6 -0
  3. data/lib/hydra-pbcore.rb +60 -1
  4. data/lib/hydra-pbcore/behaviors.rb +4 -2
  5. data/lib/hydra-pbcore/conversions.rb +88 -0
  6. data/lib/hydra-pbcore/datastream/{digital_document.rb → deprecated/digital_document.rb} +3 -2
  7. data/lib/hydra-pbcore/datastream/deprecated/document.rb +310 -0
  8. data/lib/hydra-pbcore/datastream/deprecated/instantiation.rb +261 -0
  9. data/lib/hydra-pbcore/datastream/document.rb +37 -139
  10. data/lib/hydra-pbcore/datastream/instantiation.rb +184 -223
  11. data/lib/hydra-pbcore/methods.rb +23 -2
  12. data/lib/hydra-pbcore/templates.rb +116 -0
  13. data/lib/hydra-pbcore/version.rb +1 -1
  14. data/spec/{digital_document_spec.rb → deprecated/digital_document_spec.rb} +6 -26
  15. data/spec/deprecated/document_spec.rb +282 -0
  16. data/spec/deprecated/instantiation_spec.rb +214 -0
  17. data/spec/document_spec.rb +71 -194
  18. data/spec/fixtures/converted_digital_document_rrhof_1904.xml +53 -0
  19. data/spec/fixtures/converted_digital_document_rrhof_2405.xml +46 -0
  20. data/spec/fixtures/converted_document_rrhof_2439.xml +19 -0
  21. data/spec/fixtures/converted_document_rrhof_524.xml +45 -0
  22. data/spec/fixtures/converted_instantiation_rrhof_1184.xml +39 -0
  23. data/spec/fixtures/converted_rrhof_524.xml +45 -0
  24. data/spec/fixtures/converted_rrhof_524_instantiation.xml +18 -0
  25. data/spec/fixtures/{pbcore_digital_document_template.xml → deprecated/pbcore_digital_document_template.xml} +0 -0
  26. data/spec/fixtures/{pbcore_document_template.xml → deprecated/pbcore_document_template.xml} +0 -0
  27. data/spec/fixtures/{pbcore_instantiation_template.xml → deprecated/pbcore_instantiation_template.xml} +0 -0
  28. data/spec/fixtures/{pbcore_solr_digital_document_template.xml → deprecated/pbcore_solr_digital_document_template.xml} +0 -0
  29. data/spec/fixtures/{pbcore_solr_document_template.xml → deprecated/pbcore_solr_document_template.xml} +0 -0
  30. data/spec/fixtures/{pbcore_solr_instantiation_template.xml → deprecated/pbcore_solr_instantiation_template.xml} +0 -0
  31. data/spec/fixtures/digital_instantiation.xml +56 -0
  32. data/spec/fixtures/digital_instantiation_solr.xml +1913 -0
  33. data/spec/fixtures/digital_instantiation_template.xml +33 -0
  34. data/spec/fixtures/document.xml +72 -0
  35. data/spec/fixtures/document_solr.xml +582 -0
  36. data/spec/fixtures/document_template.xml +30 -0
  37. data/spec/fixtures/integration/digital_document_rrhof_1904.xml +63 -0
  38. data/spec/fixtures/integration/digital_document_rrhof_2405.xml +62 -0
  39. data/spec/fixtures/integration/document_rrhof_2439.xml +54 -0
  40. data/spec/fixtures/integration/document_rrhof_524.xml +80 -0
  41. data/spec/fixtures/integration/instantiation_rrhof_1184.xml +44 -0
  42. data/spec/fixtures/physical_instantiation.xml +20 -0
  43. data/spec/fixtures/physical_instantiation_solr.xml +441 -0
  44. data/spec/fixtures/physical_instantiation_template.xml +18 -0
  45. data/spec/instantiation_spec.rb +180 -132
  46. data/spec/integration/conversions_spec.rb +73 -0
  47. data/spec/spec_helper.rb +37 -9
  48. data/spec/templates_spec.rb +31 -0
  49. metadata +68 -17
@@ -0,0 +1,18 @@
1
+ <pbcoreInstantiation>
2
+ <instantiationIdentifier annotation="Barcode" source="Rock and Roll Hall of Fame and Museum"/>
3
+ <instantiationDate dateType="created"/>
4
+ <instantiationPhysical source="PBCore instantiationPhysical"/>
5
+ <instantiationStandard/>
6
+ <instantiationLocation>Rock and Roll Hall of Fame and Museum,
7
+ 2809 Woodland Ave.,
8
+ Cleveland, OH, 44115
9
+ 216-515-1956
10
+ library@rockhall.org</instantiationLocation>
11
+ <instantiationMediaType source="PBCore instantiationMediaType">Moving image</instantiationMediaType>
12
+ <instantiationGenerations source="PBCore instantiationGenerations">Original</instantiationGenerations>
13
+ <instantiationColors source="PBCore instantiationColors">Color</instantiationColors>
14
+ <instantiationLanguage source="ISO 639.2" ref="http://www.loc.gov/standards/iso639-2/php/code_list.php">eng</instantiationLanguage>
15
+ <instantiationRights>
16
+ <rightsSummary/>
17
+ </instantiationRights>
18
+ </pbcoreInstantiation>
@@ -3,11 +3,20 @@ require "spec_helper"
3
3
  describe HydraPbcore::Datastream::Instantiation do
4
4
 
5
5
  before(:each) do
6
- @object_ds = HydraPbcore::Datastream::Instantiation.new(nil, nil)
6
+ @digital = HydraPbcore::Datastream::Instantiation.new(nil, nil)
7
+ @digital.define :digital
8
+ @physical = HydraPbcore::Datastream::Instantiation.new(nil, nil)
9
+ @physical.define :physical
7
10
  end
8
11
 
9
- describe ".update_indexed_attributes" do
10
- it "should update all of the fields in #xml_template and fields not requiring additional inserted nodes" do
12
+ describe "::xml_template" do
13
+ it "should have a blank default xml template" do
14
+ HydraPbcore::Datastream::Instantiation.xml_template.text.should be_empty
15
+ end
16
+ end
17
+
18
+ describe "digital instantiaions" do
19
+ it "should have these fields defined" do
11
20
  [
12
21
  [:name],
13
22
  [:location],
@@ -50,165 +59,204 @@ describe HydraPbcore::Datastream::Instantiation do
50
59
  [:audio_bit_depth],
51
60
  [:audio_channels],
52
61
  ].each do |pointer|
53
- test_val = "#{pointer.last.to_s} value"
54
- @object_ds.update_indexed_attributes( {pointer=>{"0"=>test_val}} )
55
- @object_ds.get_values(pointer).first.should == test_val
56
- @object_ds.get_values(pointer).length.should == 1
62
+ test_val = random_string
63
+ @digital.update_indexed_attributes( {pointer=>{"0"=>test_val}} )
64
+ @digital.get_values(pointer).first.should == test_val
65
+ @digital.get_values(pointer).length.should == 1
57
66
  end
58
67
  end
59
- end
60
-
61
- describe "default fields" do
62
68
 
63
- it "like media type should be 'Moving image'" do
64
- @object_ds.get_values([:media_type]).first.should == "Moving image"
69
+ it "should have default values for fields" do
70
+ @digital.media_type.first.should == "Moving image"
71
+ @digital.colors.first.should == "Color"
65
72
  end
66
73
 
67
- it "like colors should be 'Color'" do
68
- @object_ds.get_values([:colors]).first.should == "Color"
74
+ it "should have a file format and no format" do
75
+ @digital.file_format.should == [""]
76
+ @digital.format.should == []
69
77
  end
70
78
 
71
- end
72
-
73
- describe "#xml_template" do
74
- it "should return an empty xml document matching an exmplar" do
75
-
76
- # insert optional fields
77
- @object_ds.update_indexed_attributes({ [:checksum_type] => { 0 => "inserted" }} )
78
- @object_ds.update_indexed_attributes({ [:note] => { 0 => "inserted" }} )
79
- @object_ds.update_indexed_attributes({ [:checksum_value] => { 0 => "inserted" }} )
80
- @object_ds.update_indexed_attributes({ [:device] => { 0 => "inserted" }} )
81
- @object_ds.update_indexed_attributes({ [:capture_soft] => { 0 => "inserted" }} )
82
- @object_ds.update_indexed_attributes({ [:trans_soft] => { 0 => "inserted" }} )
83
- @object_ds.update_indexed_attributes({ [:operator] => { 0 => "inserted" }} )
84
- @object_ds.update_indexed_attributes({ [:trans_note] => { 0 => "inserted" }} )
85
- @object_ds.update_indexed_attributes({ [:vendor] => { 0 => "inserted" }} )
86
- @object_ds.update_indexed_attributes({ [:condition] => { 0 => "inserted" }} )
87
- @object_ds.update_indexed_attributes({ [:cleaning] => { 0 => "inserted" }} )
88
- @object_ds.update_indexed_attributes({ [:color_space] => { 0 => "inserted" }} )
89
- @object_ds.update_indexed_attributes({ [:chroma] => { 0 => "inserted" }} )
90
- @object_ds.update_indexed_attributes({ [:standard] => { 0 => "inserted" }} )
91
- @object_ds.update_indexed_attributes({ [:language] => { 0 => "inserted" }} )
79
+ it "should match an exmplar with all fields shown" do
80
+ @digital.checksum_type = "inserted"
81
+ @digital.note = "inserted"
82
+ @digital.checksum_value = "inserted"
83
+ @digital.device = "inserted"
84
+ @digital.capture_soft = "inserted"
85
+ @digital.trans_soft = "inserted"
86
+ @digital.operator = "inserted"
87
+ @digital.trans_note = "inserted"
88
+ @digital.vendor = "inserted"
89
+ @digital.condition = "inserted"
90
+ @digital.cleaning = "inserted"
91
+ @digital.color_space = "inserted"
92
+ @digital.chroma = "inserted"
93
+ @digital.standard = "inserted"
94
+ @digital.language = "inserted"
92
95
 
93
96
  # insert optional nodes using sample values
94
- @object_ds.insert_next("inserted")
95
- @object_ds.insert_previous("inserted")
96
-
97
- # Load example fixture
98
- f = fixture "pbcore_instantiation_template.xml"
99
- ref_node = Nokogiri::XML(f)
100
- f.close
101
-
102
- # Nokogiri-fy our sample document and add in namespace
103
- sample_node = Nokogiri::XML(@object_ds.to_xml)
104
- with_namespace = HydraPbcore::Behaviors.insert_pbcore_namespace(sample_node)
105
-
106
- # Save this for later...
107
- out = File.new("tmp/pbcore_instantiation_sample.xml", "w")
108
- out.write(with_namespace.to_s)
109
- out.close
97
+ @digital.insert_next("inserted")
98
+ @digital.insert_previous("inserted")
110
99
 
111
- EquivalentXml.equivalent?(ref_node, with_namespace, opts = { :element_order => false, :normalize_whitespace => true }).should be_true
112
-
113
- # TODO: reorder nodes on the instantiaion
114
- #Rockhall::Pbcore.validate(with_namespace).should be_empty
100
+ save_template @digital.to_xml, "digital_instantiation.xml"
101
+ equivalent_xml_files("digital_instantiation.xml").should be_true
115
102
  end
116
- end
103
+
104
+ it "should have different essenceTrackStandard nodes" do
105
+ @digital.video_standard = "video standard"
106
+ @digital.audio_standard = "audio standard"
107
+ @digital.get_values([{:pbcoreInstantiation=>0}, {:instantiationEssenceTrack=>0}, :essenceTrackStandard]).first.should == "video standard"
108
+ @digital.get_values([{:pbcoreInstantiation=>0}, {:instantiationEssenceTrack=>1}, :essenceTrackStandard]).first.should == "audio standard"
109
+ end
110
+
111
+ describe "solr documents" do
112
+ before(:each) do
113
+ [
114
+ "name",
115
+ "location",
116
+ "generation",
117
+ "media_type",
118
+ "file_format",
119
+ "size",
120
+ "size_units",
121
+ "colors",
122
+ "duration",
123
+ "rights_summary",
124
+ "note",
125
+ "checksum_type",
126
+ "checksum_value",
127
+ "device",
128
+ "capture_soft",
129
+ "trans_soft",
130
+ "operator",
131
+ "trans_note",
132
+ "vendor",
133
+ "condition",
134
+ "cleaning",
135
+ "color_space",
136
+ "chroma",
137
+ "video_standard",
138
+ "video_encoding",
139
+ "video_bit_rate",
140
+ "video_bit_rate_units",
141
+ "frame_rate",
142
+ "frame_size",
143
+ "video_bit_depth",
144
+ "aspect_ratio",
145
+ "audio_standard",
146
+ "audio_encoding",
147
+ "audio_bit_rate",
148
+ "audio_bit_rate_units",
149
+ "audio_sample_rate",
150
+ "audio_sample_rate_units",
151
+ "audio_bit_depth",
152
+ "audio_channels"
153
+ ].each do |field|
154
+ @digital.send("#{field}=".to_sym, field)
155
+ end
156
+ # Use a real date
157
+ @digital.date = "2012-11"
158
+ end
117
159
 
118
- describe "essence fields" do
160
+ it "should match an exmplar" do
161
+ save_template @digital.to_solr.to_xml, "digital_instantiation_solr.xml"
162
+ equivalent_xml_files("digital_instantiation_solr.xml").should be_true
163
+ end
119
164
 
120
- it "shoud have different essenceTrackStandard nodes" do
165
+ it "should display dates as they were entered" do
166
+ @digital.to_solr["date_display"].should == ["2012-11"]
167
+ end
121
168
 
122
- # Standard
123
- @object_ds.update_indexed_attributes({ [:video_standard] => { 0 => "video standard" }} )
124
- @object_ds.update_indexed_attributes({ [:audio_standard] => { 0 => "audio standard" }} )
125
- @object_ds.get_values([{:pbcoreInstantiation=>0}, {:instantiationEssenceTrack=>0}, :essenceTrackStandard]).first.should == "video standard"
126
- @object_ds.get_values([{:pbcoreInstantiation=>0}, {:instantiationEssenceTrack=>1}, :essenceTrackStandard]).first.should == "audio standard"
169
+ it "should have dates converted to ISO 8601" do
170
+ @digital.to_solr["date_dt"].should == ["2012-11-01T00:00:00Z"]
171
+ end
127
172
 
173
+ it "should not index dates as text" do
174
+ @digital.to_solr["date_t"].should be_nil
175
+ end
128
176
  end
129
-
177
+
130
178
  end
131
179
 
132
- describe ".to_solr" do
133
-
134
- before(:each) do
180
+ describe "physical instantiaions" do
181
+ it "should have these fields defined" do
135
182
  [
136
- "name",
137
- "location",
138
- "generation",
139
- "media_type",
140
- "file_format",
141
- "size",
142
- "size_units",
143
- "colors",
144
- "duration",
145
- "rights_summary",
146
- "note",
147
- "checksum_type",
148
- "checksum_value",
149
- "device",
150
- "capture_soft",
151
- "trans_soft",
152
- "operator",
153
- "trans_note",
154
- "vendor",
155
- "condition",
156
- "cleaning",
157
- "color_space",
158
- "chroma",
159
- "video_standard",
160
- "video_encoding",
161
- "video_bit_rate",
162
- "video_bit_rate_units",
163
- "frame_rate",
164
- "frame_size",
165
- "video_bit_depth",
166
- "aspect_ratio",
167
- "audio_standard",
168
- "audio_encoding",
169
- "audio_bit_rate",
170
- "audio_bit_rate_units",
171
- "audio_sample_rate",
172
- "audio_sample_rate_units",
173
- "audio_bit_depth",
174
- "audio_channels"
175
- ].each do |field|
176
- @object_ds.send("#{field}=".to_sym, field)
183
+ [:date],
184
+ [:barcode],
185
+ [:location],
186
+ [:format],
187
+ [:standard],
188
+ [:media_type],
189
+ [:generation],
190
+ [:language],
191
+ [:colors],
192
+ [:rights_summary],
193
+ [:condition_note],
194
+ [:cleaning_note]
195
+ ].each do |pointer|
196
+ test_val = random_string
197
+ @physical.update_indexed_attributes( {pointer=>{"0"=>test_val}} )
198
+ @physical.get_values(pointer).first.should == test_val
199
+ @physical.get_values(pointer).length.should == 1
177
200
  end
201
+ end
178
202
 
179
- # Use a real date
180
- @object_ds.date = "2012-11"
203
+ it "should have default values for fields" do
204
+ @physical.media_type.first.should == "Moving image"
205
+ @physical.colors.first.should == "Color"
181
206
  end
182
207
 
183
- it "should match an exmplar" do
184
- # Load example fixture
185
- f = fixture "pbcore_solr_instantiation_template.xml"
186
- ref_node = Nokogiri::XML(f)
187
- f.close
208
+ it "should have a format and no file format" do
209
+ @physical.file_format.should == []
210
+ @physical.format.should == [""]
211
+ end
188
212
 
189
- # Nokogiri-fy our sample document
190
- sample_node = Nokogiri::XML(@object_ds.to_solr.to_xml)
213
+ it "should match an exmplar with all fields shown" do
214
+ @physical.cleaning_note = "inserted"
215
+ @physical.condition_note = "inserted"
216
+ save_template @physical.to_xml, "physical_instantiation.xml"
217
+ equivalent_xml_files("physical_instantiation.xml").should be_true
218
+ end
191
219
 
192
- # Save this for later...
193
- out = File.new("tmp/pbcore_solr_instantation_sample.xml", "w")
194
- out.write(sample_node.to_s)
195
- out.close
220
+ describe "solr documents" do
221
+ before :each do
222
+ [
223
+ "date",
224
+ "barcode",
225
+ "location",
226
+ "format",
227
+ "standard",
228
+ "media_type",
229
+ "generation",
230
+ "language",
231
+ "colors",
232
+ "rights_summary",
233
+ "condition_note",
234
+ "cleaning_note"
235
+ ].each do |field|
236
+ @physical.send("#{field}=".to_sym, field)
237
+ end
238
+ # Use a real date
239
+ @physical.date = "2012-11"
240
+ end
196
241
 
197
- EquivalentXml.equivalent?(ref_node, sample_node, opts = { :element_order => false, :normalize_whitespace => true }).should be_true
198
- end
242
+ it "should match an exmplar" do
243
+ save_template @physical.to_solr.to_xml, "physical_instantiation_solr.xml"
244
+ equivalent_xml_files("physical_instantiation_solr.xml").should be_true
245
+ end
199
246
 
200
- it "should display dates as they were entered" do
201
- @object_ds.to_solr["date_display"].should == ["2012-11"]
202
- end
247
+ it "should display dates as they were entered" do
248
+ @physical.to_solr["date_display"].should == ["2012-11"]
249
+ end
203
250
 
204
- it "should have dates converted to ISO 8601" do
205
- @object_ds.to_solr["date_dt"].should == ["2012-11-01T00:00:00Z"]
206
- end
251
+ it "should have dates converted to ISO 8601" do
252
+ @physical.to_solr["date_dt"].should == ["2012-11-01T00:00:00Z"]
253
+ end
207
254
 
208
- it "should not index dates as text" do
209
- @object_ds.to_solr["date_t"].should be_nil
255
+ it "should not index dates as text" do
256
+ @physical.to_solr["date_t"].should be_nil
257
+ end
210
258
  end
211
259
 
212
260
  end
213
261
 
214
- end
262
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Converting" do
4
+
5
+ before :all do
6
+ class FakeDocument
7
+ include HydraPbcore::Conversions
8
+ end
9
+ @fake = FakeDocument.new
10
+ end
11
+
12
+ describe "HydraPbcore::Datastream::Deprecated::Document to HydraPbcore::Datastream::Document" do
13
+ it "should return a valid pbcore document" do
14
+ doc = HydraPbcore::Datastream::Deprecated::Document.from_xml(integration_fixture "document_rrhof_524.xml")
15
+ doc.to_document
16
+ save_template doc.to_xml, "converted_rrhof_524.xml"
17
+ equivalent_xml_files("converted_rrhof_524.xml").should be_true
18
+ end
19
+ it "should raise an error with the wrong class" do
20
+ lambda { @fake.to_document }.should raise_error
21
+ end
22
+ end
23
+
24
+ describe "HydraPbcore::Datastream::Deprecated::Document to HydraPbcore::Datastream::Instantiation" do
25
+ it "should return a physical instantation from an existing document" do
26
+ doc = HydraPbcore::Datastream::Deprecated::Document.from_xml(integration_fixture "document_rrhof_524.xml")
27
+ inst = doc.to_physical_instantiation
28
+ inst.should be_kind_of HydraPbcore::Datastream::Instantiation
29
+ save_template inst.to_xml, "converted_rrhof_524_instantiation.xml"
30
+ equivalent_xml_files("converted_rrhof_524_instantiation.xml").should be_true
31
+ end
32
+ it "should raise an error with the wrong class" do
33
+ lambda { @fake.to_document }.should raise_error
34
+ end
35
+ end
36
+
37
+ describe "HydraPbcore::Datastream::Deprecated::Instantiation to HydraPbcore::Datastream::Instantiation" do
38
+ it "should return a valid instantation" do
39
+ inst = HydraPbcore::Datastream::Deprecated::Instantiation.from_xml(integration_fixture "instantiation_rrhof_1184.xml")
40
+ inst.to_instantiation
41
+ save_template inst.to_xml, "converted_instantiation_rrhof_1184.xml"
42
+ equivalent_xml_files("converted_instantiation_rrhof_1184.xml").should be_true
43
+ end
44
+ it "should raise an error with the wrong class" do
45
+ lambda { @fake.to_document }.should raise_error
46
+ end
47
+ end
48
+
49
+ describe "#clean_document" do
50
+ it "should correct invalid pbcoreDigitalDocuments" do
51
+ ["digital_document_rrhof_1904.xml","digital_document_rrhof_2405.xml"].each do |file|
52
+ doc = HydraPbcore::Datastream::Deprecated::DigitalDocument.from_xml(integration_fixture file)
53
+ doc.clean_document
54
+ save_template doc.to_xml, ("converted_"+file)
55
+ equivalent_xml_files(("converted_"+file)).should be_true
56
+ save_template doc.to_pbcore_xml, "valid_pbcore.xml"
57
+ doc.valid?.should == []
58
+ end
59
+ end
60
+ it "should correct invalid pbcoreDocuments" do
61
+ ["document_rrhof_524.xml","document_rrhof_2439.xml"].each do |file|
62
+ doc = HydraPbcore::Datastream::Deprecated::Document.from_xml(integration_fixture file)
63
+ doc.to_document
64
+ doc.clean_document
65
+ save_template doc.to_xml, ("converted_"+file)
66
+ equivalent_xml_files(("converted_"+file)).should be_true
67
+ save_template doc.to_pbcore_xml, "valid_pbcore.xml"
68
+ doc.valid?.should == []
69
+ end
70
+ end
71
+ end
72
+
73
+ end