cul_scv_hydra 0.13.3 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/controllers/concerns/cul/scv/hydra/controller.rb +22 -0
- data/app/controllers/concerns/cul/scv/hydra/resolver.rb +69 -0
- data/app/controllers/concerns/cul/scv/hydra/thumbnails.rb +12 -17
- data/app/models/concerns/cul/scv/hydra/models/aggregator.rb +13 -30
- data/app/models/concerns/cul/scv/hydra/models/common.rb +1 -1
- data/app/models/concerns/cul/scv/hydra/models/image_resource.rb +1 -1
- data/app/models/content_aggregator.rb +1 -15
- data/app/models/generic_resource.rb +1 -1
- data/lib/cul_scv_hydra/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzFmMmEyZjBlOGY1OWZhOGE5MWJlMGFkYzc4NTJlMWRlYTQyY2M1NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2QwNzhmZWY5YmU5NmE5NjRkZmNmNDE3NjdiYzJhMDk4NjBlNDczYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODcyYmRjODI2Mzk5OGU3YzY0YThiYTYyMzI4YTRhYmVlY2RhNmZmZjUwNDg5
|
10
|
+
OWYxMjU2YmZjNWI2NWRkNTlkMzhhYzEyN2YzNjViZGU3NWFkNzVlYjNjYzNk
|
11
|
+
NDRkYzE4ZTUzNjU0NTM2OGY5MDg5ZTk1NzBjZWY5ZDJlZDYyNGE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDA0ZTM2YTE0NDQ3NGVjZThiMTljNGE0NjA0YmNlMDE3NTFmZTA0Nzk0OTMw
|
14
|
+
NWNiYTg1ZjNiYWJkM2U1YmNlMDQzYjBjMDE5NjA4YTM3MGMyY2ZmNTNiOTI4
|
15
|
+
NTgyZTEyZjhiMWU2MjA5NjM4YzhiZTg4NTZmZTc2MzU1ZTRlNjY=
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Cul::Scv::Hydra::Controller
|
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
|
+
def asset_url(source)
|
12
|
+
URI.join(root_url, ActionController::Base.helpers.asset_path(source))
|
13
|
+
end
|
14
|
+
|
15
|
+
def http_client
|
16
|
+
unless @http_client
|
17
|
+
@http_client ||= HTTPClient.new
|
18
|
+
end
|
19
|
+
@http_client
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'blacklight'
|
2
|
+
require 'active-fedora'
|
3
|
+
module Cul::Scv::Hydra::Resolver
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
# Whenever an action raises SolrHelper::InvalidSolrID, this block gets executed.
|
8
|
+
# Hint: the SolrHelper #get_solr_response_for_doc_id method raises this error,
|
9
|
+
# which is used in the #show action here.
|
10
|
+
self.rescue_from Blacklight::Exceptions::InvalidSolrID, :with => :invalid_solr_id_error
|
11
|
+
# When RSolr::RequestError is raised, the rsolr_request_error method is executed.
|
12
|
+
# The index action will more than likely throw this one.
|
13
|
+
# Example, when the standard query parser is used, and a user submits a "bad" query.
|
14
|
+
self.rescue_from RSolr::Error::Http, :with => :rsolr_request_error
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_solr_response_for_app_id(id=nil, extra_controller_params={})
|
18
|
+
id ||= params[:id]
|
19
|
+
solr_params = blacklight_config.default_document_solr_params.merge!(extra_controller_params)
|
20
|
+
solr_params[:fq] = "identifier_ssim:#{(id)}"
|
21
|
+
solr_response = find((blacklight_config.document_solr_request_handler || blacklight_config.qt), solr_params)
|
22
|
+
raise Blacklight::Exceptions::InvalidSolrID.new if solr_response.docs.empty?
|
23
|
+
document = SolrDocument.new(solr_response.docs.first, solr_response)
|
24
|
+
@response, @document = [solr_response, document]
|
25
|
+
end
|
26
|
+
|
27
|
+
def get
|
28
|
+
get_solr_response_for_app_id
|
29
|
+
action = params.delete(:action)
|
30
|
+
action.sub!(/s$/,'')
|
31
|
+
method_name = action + '_url'
|
32
|
+
url = send method_name.to_sym, @document[:id]
|
33
|
+
redirect_to url
|
34
|
+
end
|
35
|
+
|
36
|
+
# when solr (RSolr) throws an error (RSolr::RequestError), this method is executed.
|
37
|
+
def rsolr_request_error(exception)
|
38
|
+
if Rails.env == "development"
|
39
|
+
raise exception # Rails own code will catch and give usual Rails error page with stack trace
|
40
|
+
else
|
41
|
+
flash_notice = I18n.t('blacklight.search.errors.request_error')
|
42
|
+
# Set the notice flag if the flash[:notice] is already set to the error that we are setting.
|
43
|
+
# This is intended to stop the redirect loop error
|
44
|
+
notice = flash[:notice] if flash[:notice] == flash_notice
|
45
|
+
logger.error exception
|
46
|
+
unless notice
|
47
|
+
flash[:notice] = flash_notice
|
48
|
+
redirect_to root_path, :status => 500
|
49
|
+
else
|
50
|
+
render :file => "#{Rails.root}/public/500.html", :status => 500
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# when a request for /resolve/:action/BAD_SOLR_ID is made, this method is executed...
|
56
|
+
def invalid_solr_id_error
|
57
|
+
id = params.delete(:id)
|
58
|
+
flash[:notice] = I18n.t('blacklight.search.errors.invalid_solr_id') + " (#{id})"
|
59
|
+
redirect_to(root_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
def blacklight_solr
|
63
|
+
@solr ||= RSolr.connect(blacklight_solr_config)
|
64
|
+
end
|
65
|
+
|
66
|
+
def blacklight_solr_config
|
67
|
+
Blacklight.solr_config
|
68
|
+
end
|
69
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'httpclient'
|
1
2
|
module Cul::Scv::Hydra::Thumbnails
|
2
3
|
# some thumbnail urls
|
3
4
|
NO_THUMB = "cul_scv_hydra/crystal/file.png"
|
@@ -22,26 +23,32 @@ module Cul::Scv::Hydra::Thumbnails
|
|
22
23
|
if r_obj.respond_to? :thumbnail_info
|
23
24
|
url = r_obj.thumbnail_info
|
24
25
|
else
|
25
|
-
url = {:
|
26
|
+
url = {:asset=>(COLLECTION_THUMB),:mime=>'image/png'}
|
26
27
|
end
|
27
28
|
if url[:asset]
|
28
|
-
url
|
29
|
+
#url = {:url=>asset_url(COLLECTION_THUMB),:mime=>'image/png'}
|
30
|
+
#redirect_to asset_url(url[:asset]).to_s, status: 302
|
31
|
+
#return
|
29
32
|
end
|
30
|
-
|
33
|
+
Rails.logger.debug "thumbnail #{url[:url] || url[:asset]} #{url[:mime]}"
|
31
34
|
filename = pid + '.' + url[:mime].split('/')[1].downcase
|
32
35
|
h_cd = "filename=""#{CGI.escapeHTML(filename)}"""
|
33
36
|
headers.delete "Cache-Control"
|
34
37
|
headers["Content-Disposition"] = h_cd
|
35
38
|
headers["Content-Type"] = url[:mime]
|
36
39
|
|
37
|
-
if url[:
|
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?:/
|
38
45
|
cl = http_client
|
39
46
|
render :status => 200, :text => cl.get_content(url[:url])
|
40
47
|
return
|
41
48
|
else
|
42
49
|
render :status => 200, :text => File.read(url[:url])
|
43
50
|
return
|
44
|
-
end
|
51
|
+
end
|
45
52
|
end
|
46
53
|
|
47
54
|
def jp2_thumbnail(pid)
|
@@ -52,16 +59,4 @@ module Cul::Scv::Hydra::Thumbnails
|
|
52
59
|
return uri.sub(/info:fedora\//,'')
|
53
60
|
end
|
54
61
|
|
55
|
-
def asset_path_from_config(asset)
|
56
|
-
Rails.configuration.assets.paths.each do |dir|
|
57
|
-
result = "#{dir}/#{asset}"
|
58
|
-
return result if File.exists?(result)
|
59
|
-
end
|
60
|
-
return nil
|
61
|
-
end
|
62
|
-
|
63
|
-
def image_asset_url(source)
|
64
|
-
URI.join(root_url, ActionController::Base.helpers.asset_path(source))
|
65
|
-
end
|
66
|
-
|
67
62
|
end
|
@@ -31,42 +31,24 @@ module Cul::Scv::Hydra::Models::Aggregator
|
|
31
31
|
|
32
32
|
def solr_members(opts={})
|
33
33
|
opts = {:rows=>25,:response_format=>:solr}.merge(opts)
|
34
|
-
self.parts(opts)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#if opts[:response_format] == :solr
|
39
|
-
# return solr_result
|
40
|
-
#else
|
41
|
-
# if opts[:response_format] == :id_array
|
42
|
-
# id_array = []
|
43
|
-
# solr_result.hits.each do |hit|
|
44
|
-
# id_array << hit[SOLR_DOCUMENT_ID]
|
45
|
-
# end
|
46
|
-
# return id_array
|
47
|
-
# elsif opts[:response_format] == :load_from_solr || self.load_from_solr
|
48
|
-
# return ::ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
49
|
-
# else
|
50
|
-
# return ::ActiveFedora::SolrService.reify_solr_results(solr_result)
|
51
|
-
# end
|
52
|
-
#end
|
34
|
+
r = self.parts(opts)
|
35
|
+
members = []
|
36
|
+
r.collect {|hit| members << SolrDocument.new(hit) } unless r.blank?
|
37
|
+
members
|
53
38
|
end
|
54
39
|
|
55
40
|
def members(opts={})
|
56
|
-
|
41
|
+
parts(opts)
|
57
42
|
end
|
58
43
|
|
59
44
|
def member_ids(opts={})
|
60
|
-
opts
|
61
|
-
solr_members(opts)
|
45
|
+
solr_members(opts).collect {|hit| hit.id}
|
62
46
|
end
|
63
47
|
|
64
48
|
def thumbnail_info
|
65
|
-
|
66
|
-
members = []
|
67
|
-
r.collect {|hit| members << SolrDocument.new(hit) } unless r.blank?
|
49
|
+
members = solr_members
|
68
50
|
if members.length == 0
|
69
|
-
|
51
|
+
thumb = {:asset=>"cul_scv_hydra/crystal/file.png",:mime=>'image/png'}
|
70
52
|
else
|
71
53
|
thumb = nil
|
72
54
|
unless datastreams['structMetadata'].new?
|
@@ -75,20 +57,22 @@ module Cul::Scv::Hydra::Models::Aggregator
|
|
75
57
|
thumb = thumb_from_members(members)
|
76
58
|
end
|
77
59
|
end
|
78
|
-
return thumb || {:
|
60
|
+
return thumb || {:asset=>"cul_scv_hydra/crystal/file.png",:mime=>'image/png'}
|
79
61
|
end
|
80
62
|
|
81
63
|
private
|
82
64
|
def thumb_from_struct(members)
|
65
|
+
puts "thumb thumb_from_struct"
|
83
66
|
sm = datastreams['structMetadata']
|
84
67
|
first = sm.divs_with_attribute(false,'ORDER','1').first
|
85
68
|
if first
|
86
69
|
members.each do |member|
|
70
|
+
puts "looking for #{first["CONTENTIDS"]} in #{member["identifier_ssim"].inspect}"
|
87
71
|
if member["identifier_ssim"].include? first["CONTENTIDS"]
|
88
72
|
return thumb_from_solr_doc(member)
|
89
73
|
end
|
90
74
|
end
|
91
|
-
return
|
75
|
+
return thumb_from_solr_doc(members.first) if members.first
|
92
76
|
else
|
93
77
|
return nil
|
94
78
|
end
|
@@ -114,8 +98,7 @@ module Cul::Scv::Hydra::Models::Aggregator
|
|
114
98
|
|
115
99
|
def thumb_from_solr_doc(solr_doc)
|
116
100
|
if solr_doc and (member = ActiveFedora::Base.find(solr_doc.id, :cast=>true)).respond_to? :thumbnail_info
|
117
|
-
|
118
|
-
thumb
|
101
|
+
member.thumbnail_info
|
119
102
|
else
|
120
103
|
return nil
|
121
104
|
end
|
@@ -142,7 +142,7 @@ module Cul::Scv::Hydra::Models::Common
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def thumbnail_info
|
145
|
-
{:
|
145
|
+
{:asset=>("cul_scv_hydra/crystal/kmultiple.png"),:mime_type=>"image/png"}
|
146
146
|
end
|
147
147
|
|
148
148
|
private
|
@@ -72,7 +72,7 @@ module Cul::Scv::Hydra::Models::ImageResource
|
|
72
72
|
url = "#{DJATOKA_BASE_URL}?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }"
|
73
73
|
{:url => url, :mime => t_parms["svc.format"]}
|
74
74
|
else
|
75
|
-
return {:
|
75
|
+
return {:asset=>"cul_scv_hydra/crystal/file.png",:mime=>'image/png'}
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -1,17 +1,3 @@
|
|
1
1
|
class ContentAggregator < GenericAggregator
|
2
|
-
|
3
|
-
def thumbnail_info
|
4
|
-
_members = member_ids()
|
5
|
-
if _members.length > 1
|
6
|
-
return {:url=>image_url("cul_scv_hydra/crystal/kmultiple.png"),:mime=>'image/png'}
|
7
|
-
elsif _members.length == 0
|
8
|
-
return {:url=>image_url("cul_scv_hydra/crystal/file.png"),:mime=>'image/png'}
|
9
|
-
else
|
10
|
-
member = ActiveFedora::Base.find(_members[0], :cast=>true)
|
11
|
-
if member.respond_to? :thumbnail_info
|
12
|
-
return member.thumbnail_info
|
13
|
-
end
|
14
|
-
end
|
15
|
-
return {:url=>image_url("cul_scv_hydra/crystal/file.png"),:mime=>'image/png'}
|
16
|
-
end
|
2
|
+
|
17
3
|
end
|
@@ -79,7 +79,7 @@ class GenericResource < ::ActiveFedora::Base
|
|
79
79
|
url = "#{DJATOKA_BASE_URL}?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }"
|
80
80
|
{:url => url, :mime => t_parms["svc.format"]}
|
81
81
|
else
|
82
|
-
return {:
|
82
|
+
return {:asset => "cul_scv_hydra/crystal/file.png",:mime=>'image/png'}
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cul_scv_hydra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Armintor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blacklight
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httpclient
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: active-fedora
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +212,8 @@ files:
|
|
198
212
|
- app/assets/images/cul_scv_hydra/crystal/mp3.png
|
199
213
|
- app/assets/images/cul_scv_hydra/crystal/multimedia2.png
|
200
214
|
- app/assets/images/cul_scv_hydra/crystal/video.png
|
215
|
+
- app/controllers/concerns/cul/scv/hydra/controller.rb
|
216
|
+
- app/controllers/concerns/cul/scv/hydra/resolver.rb
|
201
217
|
- app/controllers/concerns/cul/scv/hydra/thumbnails.rb
|
202
218
|
- app/models/bag_aggregator.rb
|
203
219
|
- app/models/concerns/cul/scv/hydra/models.rb
|