ddr-models 2.8.0 → 2.9.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,6 +128,8 @@ module Ddr::Models
128
128
  if is_a? Item
129
129
  fields[ADMIN_SET_FACET] = admin_set_facet
130
130
  fields[COLLECTION_FACET] = collection_facet
131
+ fields[NESTED_PATH] = nested_path
132
+ fields[NESTED_PATH_TEXT] = nested_path
131
133
  fields[ALL_TEXT] = all_text
132
134
  end
133
135
  fields
@@ -141,6 +141,10 @@ module Ddr::Models
141
141
  has_datastream?(Ddr::Datastreams::CONTENT)
142
142
  end
143
143
 
144
+ def has_intermediate_file?
145
+ has_datastream?(Ddr::Datastreams::INTERMEDIATE_FILE)
146
+ end
147
+
144
148
  def has_extracted_text?
145
149
  has_datastream?(Ddr::Datastreams::EXTRACTED_TEXT)
146
150
  end
@@ -233,10 +237,77 @@ module Ddr::Models
233
237
  end
234
238
  end
235
239
 
240
+ def intermediate_type
241
+ if has_intermediate_file?
242
+ datastreams[Ddr::Datastreams::INTERMEDIATE_FILE]["dsMIME"]
243
+ end
244
+ end
245
+
246
+ def intermediate_path
247
+ if has_intermediate_file?
248
+ Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::INTERMEDIATE_FILE]["dsLocation"])
249
+ end
250
+ end
251
+
252
+ def intermediate_extension
253
+ if has_intermediate_file?
254
+ extensions = Ddr::Models.preferred_file_extensions
255
+ if extensions.include? intermediate_type
256
+ extensions[intermediate_type]
257
+ else
258
+ intermediate_extension_default
259
+ end
260
+ end
261
+ end
262
+
263
+ def captionable?
264
+ has_datastream?(Ddr::Datastreams::CAPTION)
265
+ end
266
+
267
+ def caption_type
268
+ if captionable?
269
+ datastreams[Ddr::Datastreams::CAPTION]["dsMIME"]
270
+ end
271
+ end
272
+
273
+ def caption_extension
274
+ if captionable?
275
+ extensions = Ddr::Models.preferred_file_extensions
276
+ if extensions.include? caption_type
277
+ extensions[caption_type]
278
+ else
279
+ caption_extension_default
280
+ end
281
+ end
282
+ end
283
+
284
+ def caption_path
285
+ if captionable?
286
+ Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::CAPTION]["dsLocation"])
287
+ end
288
+ end
289
+
236
290
  def streamable?
237
291
  has_datastream?(Ddr::Datastreams::STREAMABLE_MEDIA)
238
292
  end
239
293
 
294
+ def streamable_media_extension
295
+ if streamable?
296
+ extensions = Ddr::Models.preferred_file_extensions
297
+ if extensions.include? streamable_media_type
298
+ extensions[streamable_media_type]
299
+ else
300
+ streamable_media_extension_default
301
+ end
302
+ end
303
+ end
304
+
305
+ def streamable_media_type
306
+ if streamable?
307
+ datastreams[Ddr::Datastreams::STREAMABLE_MEDIA]["dsMIME"]
308
+ end
309
+ end
310
+
240
311
  def streamable_media_path
241
312
  if streamable?
242
313
  Ddr::Utils.path_from_uri(datastreams[Ddr::Datastreams::STREAMABLE_MEDIA]["dsLocation"])
@@ -248,6 +319,10 @@ module Ddr::Models
248
319
  self["rights_tesim"]
249
320
  end
250
321
 
322
+ def children
323
+ children_query.docs rescue []
324
+ end
325
+
251
326
  private
252
327
 
253
328
  def targets_query
@@ -296,5 +371,29 @@ module Ddr::Models
296
371
  structure['default'] || structure.values.first
297
372
  end
298
373
 
374
+ def intermediate_extension_default
375
+ datastreams[Ddr::Datastreams::INTERMEDIATE_FILE].default_file_extension
376
+ end
377
+
378
+ def caption_extension_default
379
+ datastreams[Ddr::Datastreams::CAPTION].default_file_extension
380
+ end
381
+
382
+ def streamable_media_extension_default
383
+ datastreams[Ddr::Datastreams::STREAMABLE_MEDIA].default_file_extension
384
+ end
385
+
386
+ def children_query
387
+ case self[Ddr::Index::Fields::ACTIVE_FEDORA_MODEL]
388
+ when 'Collection'
389
+ Ddr::Index::Query.build(self) do |parent|
390
+ is_member_of_collection parent.id
391
+ end
392
+ when 'Item'
393
+ Ddr::Index::Query.build(self) do |parent|
394
+ is_part_of parent.id
395
+ end
396
+ end
397
+ end
299
398
  end
300
399
  end
@@ -14,9 +14,24 @@ module Ddr::Models
14
14
  datastreams[Ddr::Datastreams::STREAMABLE_MEDIA].mimeType
15
15
  end
16
16
 
17
+ def streamable_media_extension
18
+ extensions = Ddr::Models.preferred_file_extensions
19
+ if extensions.include? streamable_media_type
20
+ extensions[streamable_media_type]
21
+ else
22
+ streamable_media_extension_default
23
+ end
24
+ end
25
+
17
26
  def streamable_media_path
18
27
  datastreams[Ddr::Datastreams::STREAMABLE_MEDIA].file_path
19
28
  end
20
29
 
30
+ private
31
+
32
+ def streamable_media_extension_default
33
+ datastreams[Ddr::Datastreams::STREAMABLE_MEDIA].default_file_extension
34
+ end
35
+
21
36
  end
22
37
  end
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "2.8.0"
3
+ VERSION = "2.9.0.rc1"
4
4
  end
5
5
  end
@@ -43,5 +43,9 @@ module Ddr::Vocab
43
43
  label: "Affiliation",
44
44
  comment: "An organizational entity associated with the object content."
45
45
 
46
+ property "nestedPath",
47
+ label: "Nested Path",
48
+ comment: "The nested/tree path to the object to be reflected in structural metadata."
49
+
46
50
  end
47
51
  end
@@ -0,0 +1,38 @@
1
+ WEBVTT
2
+
3
+ 00:01.835 --> 00:02.736
4
+ Lorem ipsum dolor sit amet.
5
+
6
+ 00:02.736 --> 00:03.837
7
+ Vestibulum pretium ligula quis nunc commodo dictum.
8
+
9
+ 00:03.837 --> 00:04.637
10
+ Donec sit amet eros rutrum, elementum neque vitae, volutpat sapien.
11
+
12
+ 00:04.637 --> 00:05.939
13
+ Vivamus sed turpis ut nisi cursus volutpat in non arcu.
14
+
15
+ 00:05.939 --> 00:07.574
16
+ Praesent dignissim lectus sed dignissim ultricies.
17
+
18
+ 00:07.574 --> 00:08.942
19
+ >> ♪ Quisque eget neque maximus, lobortis sem quis, dapibus ipsum.
20
+
21
+ 00:08.942 --> 00:09.542
22
+ Pellentesque eu risus id tellus placerat maximus.
23
+
24
+ 00:09.542 --> 00:11.778
25
+ ♪ Proin dapibus purus et magna euismod, non vestibulum ligula pellentesque.
26
+
27
+ 00:11.778 --> 00:13.980
28
+ Vivamus porttitor nibh eget nunc semper, ac tristique arcu scelerisque.
29
+
30
+ 00:13.980 --> 00:15.882
31
+ ♪ Maecenas gravida justo sit amet urna scelerisque, eget porttitor mauris interdum.
32
+
33
+ 00:15.882 --> 00:18.752
34
+ Pellentesque consectetur lacus eget bibendum rutrum.
35
+
36
+ 00:18.752 --> 00:20.387
37
+ ♪ Quisque semper magna ultrices libero iaculis fermentum.
38
+
@@ -24,6 +24,9 @@ RSpec.describe ActiveFedora::Base do
24
24
  end
25
25
  end
26
26
 
27
+ its(:captionable?) { is_expected.to be false }
28
+ it { is_expected.not_to be_captioned }
29
+
27
30
  its(:can_be_streamable?) { is_expected.to be false }
28
31
  it { is_expected.not_to be_streamable }
29
32
 
@@ -101,4 +101,156 @@ RSpec.describe Collection, type: :model do
101
101
  }
102
102
  end
103
103
 
104
+ describe "#default_structure" do
105
+ before do
106
+ allow(SecureRandom).to receive(:uuid).and_return("abc-def", "ghi-jkl", "mno-pqr", "stu-vwx", "yza-bcd", "efg-hij")
107
+ end
108
+ describe "when the collection has no items" do
109
+ let(:expected) do
110
+ xml = <<-EOS
111
+ <mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
112
+ <metsHdr>
113
+ <agent ROLE="#{Ddr::Models::Structures::Agent::ROLE_CREATOR}">
114
+ <name>#{Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT}</name>
115
+ </agent>
116
+ </metsHdr>
117
+ <structMap TYPE="#{Ddr::Models::Structure::TYPE_DEFAULT}" />
118
+ </mets>
119
+ EOS
120
+ xml
121
+ end
122
+ it "should be the appropriate structure" do
123
+ expect(subject.default_structure.to_xml).to be_equivalent_to(expected)
124
+ end
125
+ end
126
+ describe "when the collection has items" do
127
+ let(:item1) { FactoryGirl.create(:item) }
128
+ let(:item2) { FactoryGirl.create(:item) }
129
+ before do
130
+ item1.local_id = "test002"
131
+ item1.permanent_id = "ark:/99999/fk4aaa"
132
+ item1.save!
133
+ item2.local_id = "test001"
134
+ item2.permanent_id = "ark:/99999/fk4bbb"
135
+ item2.save!
136
+ subject.children << item1
137
+ subject.children << item2
138
+ subject.save!
139
+ end
140
+ after do
141
+ item1.destroy
142
+ item2.destroy
143
+ end
144
+ describe "without nested paths" do
145
+ let(:expected) do
146
+ xml = <<-EOS
147
+ <mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
148
+ <metsHdr>
149
+ <agent ROLE="#{Ddr::Models::Structures::Agent::ROLE_CREATOR}">
150
+ <name>#{Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT}</name>
151
+ </agent>
152
+ </metsHdr>
153
+ <structMap TYPE="#{Ddr::Models::Structure::TYPE_DEFAULT}">
154
+ <div ORDER="1">
155
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4bbb" />
156
+ </div>
157
+ <div ORDER="2">
158
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4aaa" />
159
+ </div>
160
+ </structMap>
161
+ </mets>
162
+ EOS
163
+ xml
164
+ end
165
+ it "should be the appropriate structure" do
166
+ expect(subject.default_structure.to_xml).to be_equivalent_to(expected)
167
+ end
168
+ end
169
+ describe "with nested paths" do
170
+ let(:item3) { FactoryGirl.create(:item) }
171
+ let(:item4) { FactoryGirl.create(:item) }
172
+ let(:item5) { FactoryGirl.create(:item) }
173
+ let(:item6) { FactoryGirl.create(:item) }
174
+ let(:expected) do
175
+ xml = <<-EOS
176
+ <mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
177
+ <metsHdr>
178
+ <agent ROLE="#{Ddr::Models::Structures::Agent::ROLE_CREATOR}">
179
+ <name>#{Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT}</name>
180
+ </agent>
181
+ </metsHdr>
182
+ <structMap TYPE="#{Ddr::Models::Structure::TYPE_DEFAULT}">
183
+ <div LABEL="foo" ORDER="1" TYPE="Directory">
184
+ <div LABEL="b&amp;apos;a&amp;quot;r&amp;quot;" ORDER="1" TYPE="Directory">
185
+ <div ORDER="1">
186
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4aaa" />
187
+ </div>
188
+ <div ORDER="2">
189
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4bbb" />
190
+ </div>
191
+ </div>
192
+ <div LABEL="baz" ORDER="2" TYPE="Directory">
193
+ <div ORDER="1">
194
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4ddd" />
195
+ </div>
196
+ <div ORDER="2">
197
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4ccc" />
198
+ </div>
199
+ </div>
200
+ <div ORDER="3">
201
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4fff" />
202
+ </div>
203
+ <div ORDER="4">
204
+ <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4eee" />
205
+ </div>
206
+ </div>
207
+ </structMap>
208
+ </mets>
209
+ EOS
210
+ xml
211
+ end
212
+ before do
213
+ item3.local_id = "test003"
214
+ item3.permanent_id = "ark:/99999/fk4ccc"
215
+ item3.save!
216
+ item4.local_id = "test004"
217
+ item4.permanent_id = "ark:/99999/fk4ddd"
218
+ item4.save!
219
+ item5.local_id = "test005"
220
+ item5.permanent_id = "ark:/99999/fk4eee"
221
+ item5.save!
222
+ item6.local_id = "test006"
223
+ item6.permanent_id = "ark:/99999/fk4fff"
224
+ item6.save!
225
+ subject.children << item3
226
+ subject.children << item4
227
+ subject.children << item5
228
+ subject.children << item6
229
+ subject.save!
230
+ item1.nested_path = %Q[foo/b'a"r"/a.doc]
231
+ item1.save!
232
+ item2.nested_path = %Q[foo/b'a"r"/b.txt]
233
+ item2.save!
234
+ item3.nested_path = %Q[foo/baz/d.pdf]
235
+ item3.save!
236
+ item4.nested_path = %Q[foo/baz/c.txt]
237
+ item4.save!
238
+ item5.nested_path = %Q[foo/f.doc]
239
+ item5.save!
240
+ item6.nested_path = %Q[foo/e.pdf]
241
+ item6.save!
242
+ end
243
+ after do
244
+ item3.destroy
245
+ item4.destroy
246
+ item5.destroy
247
+ item6.destroy
248
+ end
249
+ it "should be the appropriate structure" do
250
+ expect(subject.default_structure.to_xml).to be_equivalent_to(expected)
251
+ end
252
+ end
253
+ end
254
+ end
255
+
104
256
  end
@@ -6,6 +6,7 @@ RSpec.describe Component, type: :model, components: true do
6
6
  it_behaves_like "it has an association", :belongs_to, :target, :has_external_target, "Target"
7
7
  it_behaves_like "a non-collection model"
8
8
  it_behaves_like "a potentially publishable object"
9
+ it_behaves_like "an object that can be captioned"
9
10
  it_behaves_like "an object that can have an intermediate file"
10
11
  it_behaves_like "an object that can be streamable"
11
12
 
@@ -19,8 +20,21 @@ RSpec.describe Component, type: :model, components: true do
19
20
 
20
21
  describe "default structure" do
21
22
  describe "no content" do
22
- it "should be nil" do
23
- expect(subject.default_structure).to be_nil
23
+ let(:expected) do
24
+ xml = <<-EOS
25
+ <mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
26
+ <metsHdr>
27
+ <agent ROLE="#{Ddr::Models::Structures::Agent::ROLE_CREATOR}">
28
+ <name>#{Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT}</name>
29
+ </agent>
30
+ </metsHdr>
31
+ <structMap TYPE="#{Ddr::Models::Structure::TYPE_DEFAULT}" />
32
+ </mets>
33
+ EOS
34
+ xml
35
+ end
36
+ it "should be the appropriate structure" do
37
+ expect(described_class.new.default_structure.to_xml).to be_equivalent_to(expected)
24
38
  end
25
39
  end
26
40
  describe "has content" do
@@ -80,6 +94,22 @@ RSpec.describe Component, type: :model, components: true do
80
94
  end
81
95
  end
82
96
  end
97
+ describe "transcript" do
98
+ describe "with caption file" do
99
+ before do
100
+ allow(subject).to receive(:captioned?) { true }
101
+ end
102
+ it "has the correct structure file" do
103
+ expect(struct.uses[Ddr::Models::Structure::USE_TRANSCRIPT].first.href)
104
+ .to eq(Ddr::Datastreams::CAPTION)
105
+ end
106
+ end
107
+ describe "without caption file" do
108
+ it "has the correct structure file" do
109
+ expect(struct.uses[Ddr::Models::Structure::USE_TRANSCRIPT]).to be nil
110
+ end
111
+ end
112
+ end
83
113
  it "has the correct thumbnail image" do
84
114
  expect(struct.uses[Ddr::Models::Structure::USE_THUMBNAIL_IMAGE].first.href).to eq(Ddr::Datastreams::THUMBNAIL)
85
115
  end
@@ -27,56 +27,5 @@ module Ddr::Models
27
27
  end
28
28
  end
29
29
 
30
- describe "#default_structure" do
31
- describe "when the object has no children" do
32
- it "should be nil" do
33
- expect(subject.default_structure).to be_nil
34
- end
35
- end
36
- describe "when the object has children" do
37
- let(:child1) { FactoryGirl.create(:item) }
38
- let(:child2) { FactoryGirl.create(:item) }
39
- let(:expected) do
40
- xml = <<-EOS
41
- <mets xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink">
42
- <metsHdr>
43
- <agent ROLE="#{Ddr::Models::Structures::Agent::ROLE_CREATOR}">
44
- <name>#{Ddr::Models::Structures::Agent::NAME_REPOSITORY_DEFAULT}</name>
45
- </agent>
46
- </metsHdr>
47
- <structMap TYPE="#{Ddr::Models::Structure::TYPE_DEFAULT}">
48
- <div ORDER="1">
49
- <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4bbb" />
50
- </div>
51
- <div ORDER="2">
52
- <mptr LOCTYPE="ARK" xlink:href="ark:/99999/fk4aaa" />
53
- </div>
54
- </structMap>
55
- </mets>
56
- EOS
57
- xml
58
- end
59
- before do
60
- child1.local_id = "test002"
61
- child1.permanent_id = "ark:/99999/fk4aaa"
62
- child1.save!
63
- child2.local_id = "test001"
64
- child2.permanent_id = "ark:/99999/fk4bbb"
65
- child2.save!
66
- subject.children << child1
67
- subject.children << child2
68
- subject.save!
69
- allow(SecureRandom).to receive(:uuid).and_return("abc-def", "ghi-jkl")
70
- end
71
- after do
72
- child1.destroy
73
- child2.destroy
74
- end
75
- it "should be the appropriate structure" do
76
- expect(subject.default_structure.to_xml).to be_equivalent_to(expected)
77
- end
78
- end
79
- end
80
-
81
30
  end
82
31
  end