cul_hydra 1.9.6 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fee2757a484cdb805382ca83fcc8c21354353c85a0d05e55709f090f37d049e3
4
- data.tar.gz: 2a642263bb0225de2cb0f6bc2b1b566de3cd8d7e34e78d4dc4be0b76b3d002ab
3
+ metadata.gz: c9f2d1672e6b0151d647c2982cb663e138e8f9066ca610926a87a0e993f41e8f
4
+ data.tar.gz: 4f5c9ded2819a0e2a0456c64c88623de5e2c85fc49388ed511ad674800adf15c
5
5
  SHA512:
6
- metadata.gz: 7ac25bc59536aa135ae8a5eda1a3d26faf2dfdbc540e8f272ec73a208a956af3043a85ec7ba2741b466461c431ebfc7cc2abb65398e1ad3c8047bc84ba4cb17a
7
- data.tar.gz: c8175c178d6deab4403fa453bb7e441563aff35f1b67e17ee29d215658020aa4d2645d59808d6019766f17a8a600451787911ba62e1b9fe1cf67b80769523274
6
+ metadata.gz: e28a9ab016bc62b8ebac7f0ded9481c766db74e74f36426d1eeffd46535a7036ab3a8b80b444188c9385132b7afd67a40dfc86ed8d6a24b43de6036629ffc655
7
+ data.tar.gz: 4eac117be6bf09d0c59e4222a5c5c5422941826f4cd287b5839d09a38db580edb92277d1c838de80d7a687af472e6bac8eda52c1932b1a44aae852405e9e5f95
@@ -1,22 +1,10 @@
1
1
  module Cul::Hydra::Controller
2
2
 
3
- def asset_path_from_config(asset)
4
- Rails.configuration.assets.paths.each do |dir|
5
- result = "#{dir}/#{asset}"
6
- return result if File.exists?(result)
7
- end
8
- return nil
9
- end
10
-
11
3
  def asset_url(source)
12
4
  URI.join(root_url, ActionController::Base.helpers.asset_path(source))
13
5
  end
14
6
 
15
7
  def http_client
16
- unless @http_client
17
- @http_client ||= HTTPClient.new
18
- end
19
- @http_client
8
+ @http_client ||= HTTPClient.new
20
9
  end
21
-
22
- end
10
+ end
@@ -30,42 +30,4 @@ class AdministrativeSet < ::ActiveFedora::Base
30
30
  r.collect {|hit| members << SolrDocument.new(hit) } unless r.blank?
31
31
  members
32
32
  end
33
-
34
- def thumbnail_info
35
- members = solr_members
36
- if members.length == 0
37
- thumb = {:asset=>"cul_hydra/crystal/file.png",:mime=>'image/png'}
38
- else
39
- thumb = thumb_from_members(members)
40
- end
41
- return thumb || {:asset=>"cul_hydra/crystal/file.png",:mime=>'image/png'}
42
- end
43
-
44
- private
45
- def thumb_from_members(members)
46
- sorted = members.sort do |a,b|
47
- c = a['title_si'] <=> b['title_si']
48
- if c == 0 && a['identifier_ssim']
49
- if b['identifier_ssim']
50
- a['identifier_ssim'].delete(a.id) unless a['identifier_ssim'].length == 1
51
- b['identifier_ssim'].delete(a.id) unless b['identifier_ssim'].length == 1
52
- a['identifier_ssim'][0] <=> b['identifier_ssim'][0]
53
- else
54
- -1
55
- end
56
- else
57
- c
58
- end
59
- end
60
- thumb_from_solr_doc(sorted[0])
61
- end
62
-
63
- def thumb_from_solr_doc(solr_doc)
64
- if solr_doc and (member = ActiveFedora::Base.find(solr_doc.id, :cast=>true)).respond_to? :thumbnail_info
65
- member.thumbnail_info
66
- else
67
- return nil
68
- end
69
- end
70
-
71
33
  end
@@ -41,21 +41,6 @@ module Cul::Hydra::Models::Aggregator
41
41
  solr_members(opts).collect {|hit| hit.id}
42
42
  end
43
43
 
44
- def thumbnail_info
45
- members = solr_members
46
- if members.length == 0
47
- thumb = {:asset=>"cul_hydra/crystal/file.png",:mime=>'image/png'}
48
- else
49
- thumb = nil
50
- unless datastreams['structMetadata'].new?
51
- thumb = thumb_from_struct(members)
52
- else
53
- thumb = thumb_from_members(members)
54
- end
55
- end
56
- return thumb || {:asset=>"cul_hydra/crystal/file.png",:mime=>'image/png'}
57
- end
58
-
59
44
  # a representative image URI for this object
60
45
  # defined by the predicate https://schema.org/image
61
46
  # @return [String, URI]
@@ -68,48 +53,6 @@ module Cul::Hydra::Models::Aggregator
68
53
  end
69
54
 
70
55
  private
71
- def thumb_from_struct(members)
72
- puts "thumb thumb_from_struct"
73
- sm = datastreams['structMetadata']
74
- first = sm.divs_with_attribute(false,'ORDER','1').first
75
- if first
76
- members.each do |member|
77
- puts "looking for #{first["CONTENTIDS"]} in #{member["identifier_ssim"].inspect}"
78
- if member["identifier_ssim"].include? first["CONTENTIDS"]
79
- return thumb_from_solr_doc(member)
80
- end
81
- end
82
- return thumb_from_solr_doc(members.first) if members.first
83
- else
84
- return nil
85
- end
86
- end
87
-
88
- def thumb_from_members(members)
89
- sorted = members.sort do |a,b|
90
- c = a['title_si'] <=> b['title_si']
91
- if c == 0 && a['identifier_ssim']
92
- if b['identifier_ssim']
93
- a['identifier_ssim'].delete(a.id) unless a['identifier_ssim'].length == 1
94
- b['identifier_ssim'].delete(a.id) unless b['identifier_ssim'].length == 1
95
- a['identifier_ssim'][0] <=> b['identifier_ssim'][0]
96
- else
97
- -1
98
- end
99
- else
100
- c
101
- end
102
- end
103
- thumb_from_solr_doc(sorted[0])
104
- end
105
-
106
- def thumb_from_solr_doc(solr_doc)
107
- if solr_doc and (member = ActiveFedora::Base.find(solr_doc.id, :cast=>true)).respond_to? :thumbnail_info
108
- member.thumbnail_info
109
- else
110
- return nil
111
- end
112
- end
113
56
 
114
57
  def to_uri(obj)
115
58
  if obj.respond_to? :internal_uri
@@ -284,10 +284,6 @@ module Cul::Hydra::Models::Common
284
284
  return result
285
285
  end
286
286
 
287
- def thumbnail_info
288
- {:asset=>("cul_hydra/crystal/kmultiple.png"),:mime_type=>"image/png"}
289
- end
290
-
291
287
  def get_singular_rel(predicate)
292
288
  property = relationships(predicate).first
293
289
  return nil unless property
@@ -8,19 +8,6 @@ module Cul::Hydra::Models::ImageResource
8
8
  FORMAT_OF_PREDICATE = ActiveFedora::Predicates.short_predicate("http://purl.org/dc/terms/isFormatOf").to_s
9
9
  FORMAT_URI = RDF::URI("http://purl.org/dc/terms/format")
10
10
 
11
- DJATOKA_THUMBNAIL_PARMS = {
12
- "url_ver" => "Z39.88-2004",
13
- "svc_id" => "info:lanl-repo/svc/getRegion",
14
- "svc_val_fmt" => "info:ofi/fmt:kev:mtx:jpeg2000",
15
- "svc.format" => "image/jpeg",
16
- "svc.level" => "",
17
- "svc.rotate" => "0",
18
- "svc.scale" => "200",
19
- "svc.clayers" => ""
20
- }
21
-
22
- DJATOKA_BASE_URL = "http://iris.cul.columbia.edu:8888/resolve"
23
-
24
11
  EXIF_ORIENTATION_TO_DEGREES = {
25
12
  'top-left' => 0,
26
13
  'left-bottom' => 90,
@@ -57,33 +44,6 @@ module Cul::Hydra::Models::ImageResource
57
44
  end
58
45
  end
59
46
 
60
- def zooming?
61
- zoom = rels_int.relationships(datastreams['content'],:foaf_zooming).first
62
- return zoom.object.to_s if zoom
63
- datastreams.each do |k,v|
64
- if v.mimeType =~ /image\/jp2$/i
65
- zoom = "info:fedora/#{k.dsid}"
66
- end
67
- end
68
- return zoom
69
- end
70
-
71
- def thumbnail_info
72
- thumb = rels_int.relationships(datastreams['content'],:foaf_thumbnail).first
73
- if thumb
74
- t_dsid = thumb.object.to_s.split('/')[-1]
75
- t_url = "#{ActiveFedora.fedora_config.credentials[:url]}/objects/#{pid}/datastreams/#{t_dsid}/content"
76
- return {:url=>t_url,:mime=>datastreams[t_dsid].mimeType}
77
- elsif (zoom = self.zooming?)
78
- t_dsid = zoom.split('/')[-1]
79
- t_parms = DJATOKA_THUMBNAIL_PARMS.merge({"rft_id" => datastreams[t_dsid].dsLocation})
80
- url = "#{DJATOKA_BASE_URL}?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }"
81
- {:url => url, :mime => t_parms["svc.format"]}
82
- else
83
- return {:asset=>"cul_hydra/crystal/file.png",:mime=>'image/png'}
84
- end
85
- end
86
-
87
47
  # The number of rotational degrees required to display this image as upright
88
48
  def required_rotation_for_upright_display
89
49
  required_rotation_orientation_in_degrees = (360 - self.orientation) % 360
@@ -102,5 +62,4 @@ module Cul::Hydra::Models::ImageResource
102
62
  def orientation
103
63
  self.relationships(:orientation).present? ? EXIF_ORIENTATION_TO_DEGREES[self.relationships(:orientation).first.to_s] : 0
104
64
  end
105
-
106
65
  end
@@ -28,9 +28,6 @@ module Cul::Hydra::Models::Resource
28
28
 
29
29
  after_create :resource!
30
30
  end
31
- if self.respond_to? :has_datastream
32
- has_datastream :name => "CONTENT", :type=>::ActiveFedora::Datastream, :versionable => true
33
- end
34
31
  end
35
32
 
36
33
  def resource!
@@ -39,50 +36,4 @@ module Cul::Hydra::Models::Resource
39
36
  @metadata_is_dirty = true
40
37
  update
41
38
  end
42
-
43
- def add_content_blob(blob, opts)
44
- file_name = opts[:file_name]
45
- mime = opts[:mime_type].nil? ? mime_type(file_name) : opts[:mime_type]
46
- add_file_datastream(blob, :label=>file_name, :mimeType=>mime, :dsid => 'CONTENT')
47
- set_title_and_label( file_name, :only_if_blank=>true )
48
- if IMAGE_MIME_TYPES.include? mime
49
- blob.rewind
50
- # retrieve Nokogiri of image property RDF
51
- image_properties = Cul::Image::Properties.identify(blob)
52
- if image_properties
53
- image_prop_nodes = image_properties.nodeset
54
- relsext = datastreams['RELS-EXT']
55
- image_prop_nodes.each { |node|
56
- if node["resource"]
57
- is_literal = false
58
- object = RDF::URI.new(node["resource"])
59
- else
60
- is_literal = true
61
- object = RDF::Literal(node.text)
62
- end
63
- subject = RDF::URI(internal_uri)
64
- predicate = RDF::URI("#{node.namespace.href}#{node.name}")
65
- query = RDF::Query.new({ :subject => {predicate => :object}})
66
- relationships(predicate).dup.each { |stmt|
67
- relationships.delete(stmt)
68
- }
69
- add_relationship(predicate,object, is_literal)
70
- relationships_are_dirty=true
71
- }
72
- # add mimetype to DC:format values
73
- self.datastreams['DC'].update_values({[:format] => mime})
74
- end
75
- end
76
- blob.rewind
77
- end
78
-
79
- private
80
-
81
- # Return the mimeType for a given file name
82
- # @param [String] file_name The filename to use to get the mimeType
83
- # @return [String] mimeType for filename passed in. Default: application/octet-stream if mimeType cannot be determined
84
- def mime_type file_name
85
- mime_types = MIME::Types.of(file_name)
86
- mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
87
- end
88
39
  end
@@ -17,7 +17,6 @@ module Hydra
17
17
  autoload :Aggregator, 'cul/hydra/models/aggregator'
18
18
  autoload :Common, 'cul/hydra/models/common'
19
19
  autoload :ImageResource, 'cul/hydra/models/image_resource'
20
- autoload :LinkableResources, 'cul/hydra/models/linkable_resources'
21
20
  autoload :RelsInt, 'cul/hydra/models/rels_int'
22
21
  autoload :Resource, 'cul/hydra/models/resource'
23
22
  end
@@ -13,11 +13,11 @@ module Hydra
13
13
 
14
14
  def serialize!
15
15
  self.content = to_rels_int() if changed_attributes.include? 'relationships'
16
- clear_attribute_changes 'relationships'
16
+ clear_attribute_changes ['relationships']
17
17
  end
18
18
 
19
19
  def relationships_will_change!
20
- changed_attributes['relationships'] = nil
20
+ attribute_will_change!('relationships')
21
21
  end
22
22
 
23
23
  def content
@@ -114,7 +114,7 @@ module Hydra
114
114
  g << stmt
115
115
  end
116
116
  self.relationships_loaded = true
117
- clear_attribute_changes 'relationships'
117
+ clear_attribute_changes ['relationships']
118
118
  @graph = g
119
119
  end
120
120
 
@@ -1,4 +1,3 @@
1
- require "cul_image_props"
2
1
  require "mime/types"
3
2
  require "uri"
4
3
  require "open-uri"
@@ -53,15 +52,6 @@ class GenericResource < ::ActiveFedora::Base
53
52
  end
54
53
  end
55
54
 
56
- if self.zooming?
57
- fz = rels_int.relationships(datastreams['content'], :foaf_zooming).first.object.to_s.split('/')[-1]
58
- ds = datastreams[fz]
59
- unless ds.nil?
60
- rft_id = ds.controlGroup == 'E' ? datastreams[fz].dsLocation : legacy_content_path(ds,'info:fedora/datastreams/')
61
- solr_doc['rft_id_ss'] = rft_id
62
- end
63
- end
64
-
65
55
  if (service_ds = self.service_datastream)
66
56
  solr_doc['service_dslocation_ss'] = service_ds.dsLocation
67
57
  end
@@ -82,22 +72,6 @@ class GenericResource < ::ActiveFedora::Base
82
72
  solr_doc
83
73
  end
84
74
 
85
- def thumbnail_info
86
- thumb = rels_int.relationships(datastreams['content'],:foaf_thumbnail).first
87
- if thumb
88
- t_dsid = thumb.object.to_s.split('/')[-1]
89
- t_url = "#{ActiveFedora.fedora_config.credentials[:url]}/objects/#{pid}/datastreams/#{t_dsid}/content"
90
- return {:url=>t_url,:mime=>datastreams[t_dsid].mimeType}
91
- elsif self.zooming?
92
- t_dsid = rels_int.relationships(dsuri, :foaf_zooming).first.object.to_s.split('/')[-1]
93
- t_parms = DJATOKA_THUMBNAIL_PARMS.merge({"rft_id" => datastreams[t_dsid].dsLocation})
94
- url = "#{DJATOKA_BASE_URL}?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }"
95
- {:url => url, :mime => t_parms["svc.format"]}
96
- else
97
- return {:asset => "cul_hydra/crystal/file.png",:mime=>'image/png'}
98
- end
99
- end
100
-
101
75
  def linkable_resources
102
76
  # let's start with the known DSIDs from lindquist, then work our way back to parsing the solrized relsint
103
77
  results = []
@@ -135,17 +109,6 @@ class GenericResource < ::ActiveFedora::Base
135
109
  results
136
110
  end
137
111
 
138
- def zooming?
139
- content = datastreams['content']
140
- return false unless content
141
- zr = rels_int.relationships(content, :foaf_zooming)
142
- if (zr && zr.first)
143
- return !zr.first.blank?
144
- else
145
- false
146
- end
147
- end
148
-
149
112
  def closed?
150
113
  return access_levels.map(&:downcase).include?('closed')
151
114
  end
@@ -13,8 +13,7 @@ module ClassMethods
13
13
  recursive_member_query += ' and $cmodel <mulgara:is> <info:fedora/ldpd:' + cmodel_type + '>'
14
14
  end
15
15
 
16
- puts 'Performing query:' if verbose_output
17
- puts recursive_member_query if verbose_output
16
+ log_risearch_query(recursive_member_query, verbose_output)
18
17
 
19
18
  search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(recursive_member_query, {
20
19
  :type => 'tuples',
@@ -35,8 +34,7 @@ module ClassMethods
35
34
  'select $pid from <#ri>
36
35
  where $pid <http://purl.oclc.org/NET/CUL/memberOf> <fedora:' + pid + '>'
37
36
 
38
- puts 'Performing query:' if verbose_output
39
- puts direct_member_query if verbose_output
37
+ log_risearch_query(direct_member_query, verbose_output)
40
38
 
41
39
  search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(direct_member_query, {
42
40
  :type => 'tuples',
@@ -72,8 +70,7 @@ module ClassMethods
72
70
  where $pid <http://purl.oclc.org/NET/CUL/memberOf> <info:fedora/#{pid}>
73
71
  having $k0 <http://mulgara.org/mulgara#occursMoreThan> '0.0'^^<http://www.w3.org/2001/XMLSchema#double>;"
74
72
 
75
- puts 'Performing query:' if verbose_output
76
- puts direct_members_with_ds_query if verbose_output
73
+ log_risearch_query(direct_members_with_ds_query, verbose_output)
77
74
 
78
75
  search_response = JSON.parse(Cul::Hydra::Fedora.repository.find_by_itql(direct_members_with_ds_query, {
79
76
  :type => 'tuples',
@@ -99,8 +96,7 @@ module ClassMethods
99
96
  'select $pid from <#ri>
100
97
  where $pid <info:fedora/fedora-system:def/relations-external#isConstituentOf> <fedora:' + pid + '>'
101
98
 
102
- puts 'Performing query:' if verbose_output
103
- puts project_constituent_query if verbose_output
99
+ log_risearch_query(project_constituent_query, verbose_output)
104
100
 
105
101
  search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(project_constituent_query, {
106
102
  :type => 'tuples',
@@ -130,8 +126,7 @@ module ClassMethods
130
126
  'select $pid from <#ri>
131
127
  where $pid <http://purl.org/dc/terms/publisher> <fedora:' + pid + '>'
132
128
 
133
- puts 'Performing query:' if verbose_output
134
- puts project_constituent_query if verbose_output
129
+ log_risearch_query(project_constituent_query, verbose_output)
135
130
 
136
131
  search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(project_constituent_query, {
137
132
  :type => 'tuples',
@@ -199,6 +194,9 @@ module ClassMethods
199
194
  return pids_to_return
200
195
  end
201
196
 
197
+ def log_risearch_query(query, verbose_output = false)
198
+ puts "Performing query:\n#{query}" if verbose_output
199
+ end
202
200
  end
203
201
  extend ClassMethods
204
202
  end
@@ -1,6 +1,6 @@
1
1
  module Cul
2
2
  module Hydra
3
- VERSION = '1.9.6'
3
+ VERSION = '1.10.0'
4
4
  def self.version
5
5
  VERSION
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cul_hydra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.6
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Armintor
@@ -9,22 +9,28 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-17 00:00:00.000000000 Z
12
+ date: 2021-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '5.2'
21
+ - - "<"
19
22
  - !ruby/object:Gem::Version
20
- version: 4.2.10
23
+ version: '6.0'
21
24
  type: :runtime
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
25
- - - "~>"
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '5.2'
31
+ - - "<"
26
32
  - !ruby/object:Gem::Version
27
- version: 4.2.10
33
+ version: '6.0'
28
34
  - !ruby/object:Gem::Dependency
29
35
  name: bootstrap-sass
30
36
  requirement: !ruby/object:Gem::Requirement
@@ -115,20 +121,6 @@ dependencies:
115
121
  - - ">="
116
122
  - !ruby/object:Gem::Version
117
123
  version: 0.5.0
118
- - !ruby/object:Gem::Dependency
119
- name: cul_image_props
120
- requirement: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- type: :runtime
126
- prerelease: false
127
- version_requirements: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
124
  - !ruby/object:Gem::Dependency
133
125
  name: mods
134
126
  requirement: !ruby/object:Gem::Requirement
@@ -219,14 +211,14 @@ dependencies:
219
211
  requirements:
220
212
  - - "~>"
221
213
  - !ruby/object:Gem::Version
222
- version: 2.0.0
214
+ version: 2.1.0
223
215
  type: :runtime
224
216
  prerelease: false
225
217
  version_requirements: !ruby/object:Gem::Requirement
226
218
  requirements:
227
219
  - - "~>"
228
220
  - !ruby/object:Gem::Version
229
- version: 2.0.0
221
+ version: 2.1.0
230
222
  - !ruby/object:Gem::Dependency
231
223
  name: sprockets
232
224
  requirement: !ruby/object:Gem::Requirement
@@ -359,7 +351,6 @@ files:
359
351
  - app/controllers/concerns/cul/hydra/application_id_behavior.rb
360
352
  - app/controllers/concerns/cul/hydra/controller.rb
361
353
  - app/controllers/concerns/cul/hydra/resolver.rb
362
- - app/controllers/concerns/cul/hydra/thumbnails.rb
363
354
  - app/helpers/cul/hydra/ore_proxies_helper_behavior.rb
364
355
  - app/helpers/cul/hydra/struct_metadata_helper_behavior.rb
365
356
  - app/models/administrative_set.rb
@@ -370,7 +361,6 @@ files:
370
361
  - app/models/concerns/cul/hydra/models/aggregator.rb
371
362
  - app/models/concerns/cul/hydra/models/common.rb
372
363
  - app/models/concerns/cul/hydra/models/image_resource.rb
373
- - app/models/concerns/cul/hydra/models/linkable_resources.rb
374
364
  - app/models/concerns/cul/hydra/models/rels_int.rb
375
365
  - app/models/concerns/cul/hydra/models/resource.rb
376
366
  - app/models/concerns/nfo/common.rb
@@ -566,7 +556,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
566
556
  - !ruby/object:Gem::Version
567
557
  version: '0'
568
558
  requirements: []
569
- rubygems_version: 3.0.8
559
+ rubygems_version: 3.0.9
570
560
  signing_key:
571
561
  specification_version: 4
572
562
  summary: ActiveFedora, OM, and Solrizer implementations for CUL repository apps
@@ -1,62 +0,0 @@
1
- require 'httpclient'
2
- module Cul::Hydra::Thumbnails
3
- # some thumbnail urls
4
- NO_THUMB = "cul_hydra/crystal/file.png"
5
- BROKEN_THUMB = "cul_hydra/crystal/file_broken.png"
6
- COLLECTION_THUMB = "cul_hydra/crystal/kmultiple.png"
7
- AUDIO_THUMB = "cul_hydra/crystal/sound.png"
8
- # some rel predicates
9
- FORMAT = "http://purl.org/dc/elements/1.1/format"
10
- MEMBER_OF = "http://purl.oclc.org/NET/CUL/memberOf"
11
- HAS_MODEL = "info:fedora/fedora-system:def/model#hasModel"
12
- IMAGE_WIDTH = "http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/BASIC/imageWidth"
13
- IMAGE_LENGTH = "http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/BASIC/imageLength"
14
-
15
- def show
16
- pid = params[:id].split(/@/)[0]
17
- get_by_pid(pid)
18
- end
19
-
20
- def get_by_pid(pid)
21
- r_obj = ActiveFedora::Base.find(pid, :cast=>true)
22
-
23
- if r_obj.respond_to? :thumbnail_info
24
- url = r_obj.thumbnail_info
25
- else
26
- url = {:asset=>(COLLECTION_THUMB),:mime=>'image/png'}
27
- end
28
- if url[:asset]
29
- #url = {:url=>asset_url(COLLECTION_THUMB),:mime=>'image/png'}
30
- #redirect_to asset_url(url[:asset]).to_s, status: 302
31
- #return
32
- end
33
- Rails.logger.debug "thumbnail #{url[:url] || url[:asset]} #{url[:mime]}"
34
- filename = pid + '.' + url[:mime].split('/')[1].downcase
35
- h_cd = "filename=""#{CGI.escapeHTML(filename)}"""
36
- headers.delete "Cache-Control"
37
- headers["Content-Disposition"] = h_cd
38
- headers["Content-Type"] = url[:mime]
39
-
40
- if url[:asset]
41
- full_path = Rails.application.assets.resolve(url[:asset]).to_path
42
- render :status => 200, :text => File.read(full_path)
43
- return
44
- elsif url[:url].to_s =~ /^https?:/
45
- cl = http_client
46
- render :status => 200, :text => cl.get_content(url[:url])
47
- return
48
- else
49
- render :status => 200, :text => File.read(url[:url])
50
- return
51
- end
52
- end
53
-
54
- def jp2_thumbnail(pid)
55
- {:url => ActiveFedora.fedora_config.credentials[:url] + '/objects/' + pid + '/methods/ldpd:sdef.Image/getView?max=250', :mime => 'image/jpeg'}
56
- end
57
-
58
- def pid_from_uri(uri)
59
- return uri.sub(/info:fedora\//,'')
60
- end
61
-
62
- end
@@ -1,108 +0,0 @@
1
- module Cul::Hydra::Models::LinkableResources
2
- include Cul::Hydra::Fedora::UrlHelperBehavior
3
- # so as to avoid including all the url hepers via:
4
- ## include Rails.application.routes.url_helpers
5
- # we are just going to delegate
6
- delegate :fedora_content_path, :to => 'Rails.application.routes.url_helpers'
7
- delegate :cache_path, :to => 'Rails.application.routes.url_helpers'
8
-
9
- def http_client
10
- unless @http_client
11
- @http_client ||= HTTPClient.new
12
- @http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
- uname = Cul::Hydra::Fedora.repository.config[:user]
14
- pwd = Cul::Hydra::Fedora.repository.config[:password]
15
- @http_client.set_auth(nil, uname, pwd)
16
- end
17
- @http_client
18
- end
19
-
20
- def linkable_resources
21
- r = self.parts(:response_format => :solr)
22
- return [] if r.blank?
23
- members = r.collect {|hit|
24
- SolrDocument.new(hit)
25
- }
26
- members.delete_if { |sd| (sd[:has_model_ssim] & ["info:fedora/ldpd:Resource"]).blank? }
27
- case self.route_as
28
- when "zoomingimage"
29
- results = members.collect {|doc| image_resource(doc)}
30
- base_id = self.pid
31
- url = fedora_ds_url(base_id, 'SOURCE') + '/content'
32
- head_req = http_client().head(url)
33
- file_size = head_req.header["Content-Length"].first.to_i
34
- results << {
35
- :dimensions => "Original",
36
- :mime_type => "image/jp2",
37
- :uri=>base_id, :block=>"SOURCE", :filename=>base_id + "_source.jp2",
38
- :content_models=>[]}
39
- when "audio"
40
- results = members.collect {|doc| audio_resource(doc)}
41
- when "image"
42
- results = members.collect {|doc| image_resource(doc)}
43
- else
44
- raise "Unknown format #{self.route_as}"
45
- end
46
- return results
47
- end
48
-
49
- def basic_resource(document)
50
- res = {}
51
- res[:pid] = document["id"]
52
- res[:dsid] = "CONTENT"
53
- res[:mime_type] = document["dc_format_ssm"] ? document["dc_format_ssm"].first : "application/octect-stream"
54
- res[:content_models] = document["has_model_ssim"]
55
- res[:file_size] = document["extent_ssim"].first.to_i
56
- res[:size] = (document["extent_ssim"].first.to_i / 1024).to_s + " Kb"
57
- res
58
- end
59
-
60
- def image_resource(document)
61
- res = basic_resource(document)
62
- if document["image_width_ssim"]
63
- res[:dimensions] = document["image_width_ssim"].first + " x " + document["image_length_ssim"].first
64
- res[:width] = document["image_width_ssim"].first
65
- res[:height] = document["image_length_ssim"].first
66
- else
67
- res[:dimensions] = "? x ?"
68
- res[:width] = "0"
69
- res[:height] = "0"
70
- end
71
- base_id = document["id"]
72
- base_filename = base_id.gsub(/\:/,"")
73
- img_filename = base_filename + "." + document["dc_format_ssm"].first.gsub(/^[^\/]+\//,"")
74
- res[:filename] = img_filename
75
- res[:block] = "CONTENT"
76
- res[:mime_type] = document["dc_format_ssm"] ? document["dc_format_ssm"].first : "application/octect-stream"
77
- res[:content_models] = document["has_model_ssim"]
78
- res[:file_size] = document["extent_ssim"].first.to_i
79
- res[:size] = (document["extent_ssim"].first.to_i / 1024).to_s + " Kb"
80
- res[:uri] = base_id
81
- res
82
- end
83
-
84
- def audio_resource(document)
85
- res = basic_resource(document)
86
- base_id = document["id"]
87
- base_filename = base_id.gsub(/\:/,"")
88
- if res[:mime_type] =~ /wav/
89
- ext = 'wav'
90
- elsif res[:mime_type] =~ /mpeg/
91
- ext = 'mp3'
92
- else
93
- ext = 'bin'
94
- end
95
- filename = base_filename + "." + ext
96
- dc_filename = base_filename + "_dc.xml"
97
- res[:uri] = base_id
98
- res[:block] = "CONTENT"
99
- res[:filename] = filename
100
- res[:dc_path] = fedora_content_path(:download_method=>"show_pretty", :uri=>base_id, :block=>"DC", :filename=>dc_filename)
101
- res[:mime_type] = document["dc_format_ssm"] ? document["dc_format_ssm"].first : "application/octect-stream"
102
- res[:content_models] = document["has_model_ssim"]
103
- res[:file_size] = document["extent_ssim"].first.to_i
104
- res[:size] = (document["extent_ssim"].first.to_i / 1024).to_s + " Kb"
105
- res
106
- end
107
-
108
- end