dor-services 5.10.4 → 5.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dor/models/identifiable.rb +19 -0
- data/lib/dor/models/publishable.rb +55 -0
- data/lib/dor/models/releaseable.rb +0 -8
- data/lib/dor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b43e614c997ae6368c5a7b14cc78ce07ae8cbfc8
|
4
|
+
data.tar.gz: aa9935c4a84262fcd5f6f8b18f3f8eead8530a5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cde8359eab91eaa96ff7773ec814b0bcfafa8a6e208c7179aa8b82bfb050b1bce9b853b7d705b38265e300482813c9f72cacf6e3e83e4de091e8c8b34bc7f412
|
7
|
+
data.tar.gz: 3cc30b9150f706c3f97858c6bf8109d6529f24f16b24d242f9bfa4cb38fddd287fc63c5893632a46cdab336633568ef5e168d8f8c0b11589ba10d5e25164a50c
|
@@ -205,6 +205,25 @@ module Dor
|
|
205
205
|
desc_md_ds_title.present? ? desc_md_ds_title : default_title
|
206
206
|
end
|
207
207
|
|
208
|
+
# a regex that can be used to identify the last part of a druid (e.g. oo000oo0001)
|
209
|
+
# @return [Regex] a regular expression to identify the ID part of the druid
|
210
|
+
def pid_regex
|
211
|
+
/[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}[0-9]{4}/
|
212
|
+
end
|
213
|
+
|
214
|
+
# a regex that can be used to identify a full druid with prefix (e.g. druid:oo000oo0001)
|
215
|
+
# @return [Regex] a regular expression to identify a full druid
|
216
|
+
def druid_regex
|
217
|
+
/druid:#{pid_regex}/
|
218
|
+
end
|
219
|
+
|
220
|
+
# Since purl does not use the druid: prefix but much of dor does, use this function to strip the druid: if needed
|
221
|
+
# @return [String] the druid sans the druid: or if there was no druid: prefix, the entire string you passed
|
222
|
+
def remove_druid_prefix(druid=id)
|
223
|
+
result=druid.match(/#{pid_regex}/)
|
224
|
+
result.nil? ? druid : result[0] # if no matches, return the string passed in, otherwise return the match
|
225
|
+
end
|
226
|
+
|
208
227
|
private
|
209
228
|
|
210
229
|
def solrize_related_obj_titles(solr_doc, relationships, title_hash, union_field_name, nonhydrus_field_name, hydrus_field_name)
|
@@ -10,6 +10,59 @@ module Dor
|
|
10
10
|
include Itemizable
|
11
11
|
include Rightsable
|
12
12
|
|
13
|
+
# Compute the thumbnail for this object following the rules at https://consul.stanford.edu/display/chimera/The+Rules+of+Thumb
|
14
|
+
# @return [String] the computed thumb filename, with the druid prefix and a slash in front of it, e.g. oo000oo0001/filenamewith space.jp2
|
15
|
+
def thumb
|
16
|
+
return if contentMetadata.nil?
|
17
|
+
cm = contentMetadata.ng_xml
|
18
|
+
mime_type_finder = "@mimetype='image/jp2' or @mimeType='image/jp2'" # allow the mimetype attribute to be lower or camelcase when searching to make it more robust
|
19
|
+
thumb_image=nil
|
20
|
+
|
21
|
+
# these are the finders we will use to search for a thumb resource in contentMetadata, they will be searched in the order provided, stopping when one is reached
|
22
|
+
thumb_xpath_finders = [
|
23
|
+
{image_type: 'local', finder: "/contentMetadata/resource[@type='thumb' and @thumb='yes']/file[#{mime_type_finder}]"}, # first find a file of mimetype jp2 explicitly marked as a thumb in the resource type and with a thumb=yes attribute
|
24
|
+
{image_type: 'external', finder: "/contentMetadata/resource[@type='thumb' and @thumb='yes']/externalFile[#{mime_type_finder}]"}, # same thing for external files
|
25
|
+
{image_type: 'local', finder: "/contentMetadata/resource[(@type='page' or @type='image') and @thumb='yes']/file[#{mime_type_finder}]"},# next find any image or page resource types with the thumb=yes attribute of mimetype jp2
|
26
|
+
{image_type: 'external', finder: "/contentMetadata/resource[(@type='page' or @type='image') and @thumb='yes']/externalFile[#{mime_type_finder}]"},# same thing for external file
|
27
|
+
{image_type: 'local', finder: "/contentMetadata/resource[@type='thumb']/file[#{mime_type_finder}]"}, # next find a file of mimetype jp2 and resource type=thumb but not marked with the thumb directive
|
28
|
+
{image_type: 'external', finder: "/contentMetadata/resource[@type='thumb']/externalFile[#{mime_type_finder}]"}, # same thing for external file
|
29
|
+
{image_type: 'local', finder: "/contentMetadata/resource[@type='page' or @type='image']/file[#{mime_type_finder}]"}, # finally find the first page or image resource of mimetype jp2
|
30
|
+
{image_type: 'external', finder: "/contentMetadata/resource[@type='page' or @type='image']/externalFile[#{mime_type_finder}]"} # same thing for external file
|
31
|
+
]
|
32
|
+
|
33
|
+
thumb_xpath_finders.each do |search_path|
|
34
|
+
thumb_files = cm.xpath(search_path[:finder]) # look for a thumb
|
35
|
+
if thumb_files.size > 0 # if we find one, return the filename based on whether it is a local file or external file
|
36
|
+
if search_path[:image_type] == 'local'
|
37
|
+
thumb_image="#{remove_druid_prefix}/#{thumb_files[0]['id']}"
|
38
|
+
else
|
39
|
+
thumb_image="#{remove_druid_prefix(thumb_files[0]['objectId'])}/#{thumb_files[0]['fileId']}"
|
40
|
+
end
|
41
|
+
break # break out of the loop so we stop searching
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
thumb_image
|
46
|
+
end
|
47
|
+
|
48
|
+
# Return a URI encoded version of the thumb image for use by indexers (leaving the extension of the filename)
|
49
|
+
# @return [String] URI encoded version of the thumb with the druid prefix, e.g. oo000oo0001%2Ffilenamewith%20space.jp2
|
50
|
+
def encoded_thumb
|
51
|
+
thumb_image = thumb # store the result locally, so we don't have to compute each time we use it below
|
52
|
+
return unless thumb_image
|
53
|
+
thumb_druid=thumb_image.split('/').first # the druid (before the first slash)
|
54
|
+
thumb_filename=thumb_image.split(/#{pid_regex}[\/]/).last # everything after the druid
|
55
|
+
"#{thumb_druid}%2F#{URI.escape(thumb_filename)}"
|
56
|
+
end
|
57
|
+
|
58
|
+
# Return a full qualified thumbnail image URL if the thumb is computable
|
59
|
+
# @return [String] fully qualified image URL for the computed thumbnail, e.g. https://stacks.stanford.edu/image/iiif/oo000oo0001%2Ffilenamewith%20space/full
|
60
|
+
def thumb_url
|
61
|
+
return unless encoded_thumb
|
62
|
+
thumb_basename=File.basename(encoded_thumb, File.extname(encoded_thumb)) # strip the extension for URL generation
|
63
|
+
"https://#{Dor::Config.stacks.host}/image/iiif/#{thumb_basename}/full/!400,400/0/default.jpg"
|
64
|
+
end
|
65
|
+
|
13
66
|
def public_relationships
|
14
67
|
include_elements = ['fedora:isMemberOf', 'fedora:isMemberOfCollection', 'fedora:isConstituentOf']
|
15
68
|
rels_doc = Nokogiri::XML(datastreams['RELS-EXT'].content)
|
@@ -41,9 +94,11 @@ module Dor
|
|
41
94
|
rels = public_relationships.root
|
42
95
|
pub.add_child(rels.clone) unless rels.nil? # TODO: Should never be nil in practice; working around an ActiveFedora quirk for testing
|
43
96
|
pub.add_child(generate_dublin_core.root.clone)
|
97
|
+
pub.add_child(Nokogiri::XML(generate_public_desc_md).root.clone) if metadata_format == 'mods'
|
44
98
|
pub.add_child(Nokogiri(generate_release_xml).root.clone) unless release_xml.children.size == 0 # If there are no release_tags, this prevents an empty <releaseData/> from being added
|
45
99
|
# Note we cannot base this on if an individual object has release tags or not, because the collection may cause one to be generated for an item,
|
46
100
|
# so we need to calculate it and then look at the final result.s
|
101
|
+
pub.add_child(Nokogiri("<thumb>#{thumb}</thumb>").root.clone) unless thumb.nil?
|
47
102
|
new_pub = Nokogiri::XML(pub.to_xml) { |x| x.noblanks }
|
48
103
|
new_pub.encoding = 'UTF-8'
|
49
104
|
new_pub.to_xml
|
@@ -284,14 +284,6 @@ module Dor
|
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
-
# Since purl does not use the druid: prefix but much of dor does, use this function to strip the druid: if needed
|
288
|
-
# @return [String] the druid sans the druid: or if there was no druid: prefix, the entire string you passed
|
289
|
-
def remove_druid_prefix
|
290
|
-
druid_prefix = 'druid:'
|
291
|
-
return id.split(druid_prefix)[1] if id.split(druid_prefix).size > 1
|
292
|
-
druid
|
293
|
-
end
|
294
|
-
|
295
287
|
# Take the and create the entire purl url that will usable for the open method in open-uri, returns http
|
296
288
|
# @return [String] the full url
|
297
289
|
def form_purl_url
|
data/lib/dor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dor-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Klein
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2016-
|
17
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: active-fedora
|