cul_scv_hydra 0.22.6 → 0.22.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/cul/hydra/controller.rb +22 -0
  3. data/app/controllers/concerns/cul/hydra/resolver.rb +69 -0
  4. data/app/controllers/concerns/cul/hydra/thumbnails.rb +62 -0
  5. data/app/controllers/concerns/cul/scv/hydra/controller.rb +3 -19
  6. data/app/controllers/concerns/cul/scv/hydra/resolver.rb +2 -65
  7. data/app/controllers/concerns/cul/scv/hydra/thumbnails.rb +3 -59
  8. data/app/models/concept.rb +1 -1
  9. data/app/models/concerns/cul/hydra/models.rb +24 -0
  10. data/app/models/concerns/cul/hydra/models/aggregator.rb +121 -0
  11. data/app/models/concerns/cul/hydra/models/common.rb +220 -0
  12. data/app/models/concerns/cul/hydra/models/image_resource.rb +78 -0
  13. data/app/models/concerns/cul/hydra/models/linkable_resources.rb +108 -0
  14. data/app/models/concerns/cul/hydra/models/resource.rb +87 -0
  15. data/app/models/concerns/cul/scv/hydra/models.rb +1 -13
  16. data/app/models/concerns/cul/scv/hydra/models/aggregator.rb +1 -116
  17. data/app/models/concerns/cul/scv/hydra/models/common.rb +1 -213
  18. data/app/models/concerns/cul/scv/hydra/models/image_resource.rb +3 -75
  19. data/app/models/concerns/cul/scv/hydra/models/linkable_resources.rb +3 -105
  20. data/app/models/concerns/cul/scv/hydra/models/resource.rb +2 -83
  21. data/app/models/cul/hydra/datastreams/dc_metadata.rb +107 -0
  22. data/app/models/cul/hydra/datastreams/mods_document.rb +195 -0
  23. data/app/models/cul/hydra/datastreams/struct_metadata.rb +176 -0
  24. data/app/models/cul/scv/hydra/datastreams/dc_metadata.rb +5 -104
  25. data/app/models/cul/scv/hydra/datastreams/mods_document.rb +5 -178
  26. data/app/models/cul/scv/hydra/datastreams/struct_metadata.rb +5 -174
  27. data/app/models/dc_document.rb +1 -1
  28. data/app/models/generic_aggregator.rb +5 -5
  29. data/app/models/generic_object.rb +2 -2
  30. data/app/models/generic_resource.rb +4 -4
  31. data/app/models/mets_structured_aggregator.rb +2 -2
  32. data/app/models/resource.rb +3 -3
  33. data/app/models/resource_aggregator.rb +3 -3
  34. data/fixtures/spec/CUL_MODS/mods-subjects.xml +24 -0
  35. data/lib/cul_hydra.rb +18 -0
  36. data/lib/cul_hydra/access_controls_enforcement.rb +53 -0
  37. data/lib/cul_hydra/controllers.rb +13 -0
  38. data/lib/cul_hydra/controllers/aggregates.rb +93 -0
  39. data/lib/cul_hydra/controllers/aggregator_controller_helper.rb +27 -0
  40. data/lib/cul_hydra/controllers/catalog.rb +12 -0
  41. data/lib/cul_hydra/controllers/content_aggregators.rb +81 -0
  42. data/lib/cul_hydra/controllers/datastreams.rb +145 -0
  43. data/lib/cul_hydra/controllers/helpers.rb +10 -0
  44. data/lib/{cul_scv_hydra → cul_hydra}/controllers/helpers/active_fedora_helper_behavior.rb +1 -1
  45. data/lib/{cul_scv_hydra → cul_hydra}/controllers/helpers/application_helper_behavior.rb +1 -1
  46. data/lib/{cul_scv_hydra → cul_hydra}/controllers/helpers/dc_metadata_helper_behavior.rb +1 -1
  47. data/lib/{cul_scv_hydra → cul_hydra}/controllers/helpers/hydra_assets_helper_behavior.rb +1 -1
  48. data/lib/{cul_scv_hydra → cul_hydra}/controllers/helpers/hydra_autocomplete_helper_behavior.rb +1 -1
  49. data/lib/{cul_scv_hydra → cul_hydra}/controllers/helpers/hydra_uploader_helper_behavior.rb +1 -1
  50. data/lib/{cul_scv_hydra → cul_hydra}/controllers/helpers/resources_helper_behavior.rb +1 -1
  51. data/lib/cul_hydra/controllers/resources.rb +161 -0
  52. data/lib/cul_hydra/controllers/static_image_aggregators.rb +105 -0
  53. data/lib/cul_hydra/controllers/suggestions.rb +126 -0
  54. data/lib/cul_hydra/controllers/terms.rb +205 -0
  55. data/lib/cul_hydra/engine.rb +31 -0
  56. data/lib/cul_hydra/fedora.rb +41 -0
  57. data/lib/cul_hydra/fedora/dummy_object.rb +37 -0
  58. data/lib/cul_hydra/fedora/rubydora_patch.rb +16 -0
  59. data/lib/cul_hydra/fedora/url_helper_behavior.rb +32 -0
  60. data/lib/cul_hydra/indexer.rb +84 -0
  61. data/lib/cul_hydra/om.rb +7 -0
  62. data/lib/cul_hydra/om/standard_mods.rb +115 -0
  63. data/lib/cul_hydra/risearch_members.rb +92 -0
  64. data/lib/cul_hydra/solrizer.rb +10 -0
  65. data/lib/cul_hydra/solrizer/extractor.rb +27 -0
  66. data/lib/cul_hydra/solrizer/mods_fieldable.rb +435 -0
  67. data/lib/cul_hydra/solrizer/terminology_based_solrizer.rb +35 -0
  68. data/lib/cul_hydra/solrizer/value_mapper.rb +46 -0
  69. data/lib/{cul_scv_hydra/solrizer/field_mapper.rb → cul_hydra/solrizer_patch.rb} +0 -0
  70. data/lib/cul_hydra/version.rb +8 -0
  71. data/lib/cul_hydra/version.rb~ +8 -0
  72. data/lib/cul_scv_fedora/dummy_object.rb +1 -30
  73. data/lib/cul_scv_fedora/rubydora_patch.rb +3 -7
  74. data/lib/cul_scv_fedora/url_helper_behavior.rb +3 -23
  75. data/lib/cul_scv_hydra.rb +5 -32
  76. data/lib/cul_scv_hydra/access_controls_enforcement.rb +3 -50
  77. data/lib/cul_scv_hydra/controllers.rb +10 -10
  78. data/lib/cul_scv_hydra/controllers/aggregates.rb +1 -86
  79. data/lib/cul_scv_hydra/controllers/aggregator_controller_helper.rb +4 -23
  80. data/lib/cul_scv_hydra/controllers/catalog.rb +5 -9
  81. data/lib/cul_scv_hydra/controllers/content_aggregators.rb +4 -77
  82. data/lib/cul_scv_hydra/controllers/datastreams.rb +3 -140
  83. data/lib/cul_scv_hydra/controllers/helpers.rb +44 -8
  84. data/lib/cul_scv_hydra/controllers/resources.rb +4 -157
  85. data/lib/cul_scv_hydra/controllers/static_image_aggregators.rb +4 -100
  86. data/lib/cul_scv_hydra/controllers/suggestions.rb +4 -122
  87. data/lib/cul_scv_hydra/controllers/terms.rb +4 -201
  88. data/lib/cul_scv_hydra/engine.rb +1 -1
  89. data/lib/cul_scv_hydra/indexer.rb +3 -82
  90. data/lib/cul_scv_hydra/om.rb +2 -2
  91. data/lib/cul_scv_hydra/om/standard_mods.rb +1 -108
  92. data/lib/cul_scv_hydra/risearch_members.rb +4 -89
  93. data/lib/cul_scv_hydra/solrizer.rb +5 -6
  94. data/lib/cul_scv_hydra/solrizer/extractor.rb +1 -25
  95. data/lib/cul_scv_hydra/solrizer/scv_mods_fieldable.rb +4 -429
  96. data/lib/cul_scv_hydra/solrizer/terminology_based_solrizer.rb +4 -32
  97. data/lib/cul_scv_hydra/solrizer/value_mapper.rb +1 -44
  98. data/lib/cul_scv_hydra/version.rb +5 -5
  99. data/lib/tasks/index.rake +2 -2
  100. data/lib/tasks/transform.rake +23 -0
  101. metadata +55 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00fd038a4aa096dc2b63253c547b794f99af8a2d
4
- data.tar.gz: 95dcb3790b7ab83bf2ea040dfab268ccc9a0e36f
3
+ metadata.gz: fee4c2f931371cbd1957daca914793b419d4d878
4
+ data.tar.gz: 9ee170c5764a6c01ec50efffd499569c3d344bed
5
5
  SHA512:
6
- metadata.gz: 56d23237481df7aa4ebf53ee8223147ae77a72785aaad96b737101f088aba67cc781a019c0be5e62d58bf5119b7aba00a03b2682bd1a904e1a4599381593c0af
7
- data.tar.gz: e5a5fdb9f79ec2e9260b2612ab6b75909e52d9f73f6b97dc4ec659fab83669c6d13ceedd03f39754e4c7eafec1be1b976b36aa4f35bd5e112756646e7a9a0208
6
+ metadata.gz: e225c9555c17775be784def42a334e76b33aebe30b2181d6cb10318d2dd40b9515bee46c732d0f8f40f247e557779ba93b010db5cdd5f3da6b0d1e85c0308a8c
7
+ data.tar.gz: 6927ae1cfd3b4d79e50db49e20e16cab6543156189ac81214ec3bd1137b02f8a91cc20fab3ae6752fe944e1c880fd6ebb62f261966ac4602537f862bba53edee
@@ -0,0 +1,22 @@
1
+ module Cul::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::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
@@ -0,0 +1,62 @@
1
+ require 'httpclient'
2
+ module Cul::Hydra::Thumbnails
3
+ # some thumbnail urls
4
+ NO_THUMB = "cul_scv_hydra/crystal/file.png"
5
+ BROKEN_THUMB = "cul_scv_hydra/crystal/file_broken.png"
6
+ COLLECTION_THUMB = "cul_scv_hydra/crystal/kmultiple.png"
7
+ AUDIO_THUMB = "cul_scv_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,22 +1,6 @@
1
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
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ include Cul::Hydra::Controller
9
5
  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
6
  end
@@ -1,69 +1,6 @@
1
- require 'blacklight'
2
- require 'active-fedora'
3
1
  module Cul::Scv::Hydra::Resolver
4
2
  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
3
+ included do
4
+ include Cul::Hydra::Resolver
68
5
  end
69
6
  end
@@ -1,62 +1,6 @@
1
- require 'httpclient'
2
1
  module Cul::Scv::Hydra::Thumbnails
3
- # some thumbnail urls
4
- NO_THUMB = "cul_scv_hydra/crystal/file.png"
5
- BROKEN_THUMB = "cul_scv_hydra/crystal/file_broken.png"
6
- COLLECTION_THUMB = "cul_scv_hydra/crystal/kmultiple.png"
7
- AUDIO_THUMB = "cul_scv_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)
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ include Cul::Hydra::Thumbnails
18
5
  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
6
  end
@@ -4,7 +4,7 @@ class Concept < GenericAggregator
4
4
  include ::ActiveFedora::FinderMethods::RepositoryMethods
5
5
  include ::ActiveFedora::DatastreamCollections
6
6
  include ::Hydra::ModelMethods
7
- include Cul::Scv::Hydra::Models::Common
7
+ include Cul::Hydra::Models::Common
8
8
 
9
9
  has_and_belongs_to_many :containers, :property=>:cul_member_of, :class_name=>'ActiveFedora::Base'
10
10
 
@@ -0,0 +1,24 @@
1
+ require "active-fedora"
2
+ require "cul_scv_hydra/om"
3
+ require 'uri'
4
+ require 'rdf'
5
+ module Cul
6
+ module Hydra
7
+ module Models
8
+ AGGREGATOR_TYPE = RDF::CUL.Aggregator
9
+ RESOURCE_TYPE = RDF::CUL.Resource
10
+ MEMBER_OF = RDF::CUL.memberOf
11
+ MEMBER_SPARQL = <<-SPARQL
12
+ SELECT ?pid WHERE { ?pid <http://purl.oclc.org/NET/CUL/memberOf> <info:fedora/%PID%> }
13
+ SPARQL
14
+ MEMBER_ITQL = <<-ITQL
15
+ select $pid from <#ri> where $pid <http://purl.oclc.org/NET/CUL/memberOf> <info:fedora/%PID%>
16
+ ITQL
17
+ autoload :Aggregator, 'cul/hydra/models/aggregator'
18
+ autoload :Common, 'cul/hydra/models/common'
19
+ autoload :ImageResource, 'cul/hydra/models/image_resource'
20
+ autoload :LinkableResources, 'cul/hydra/models/linkable_resources'
21
+ autoload :Resource, 'cul/hydra/models/resource'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,121 @@
1
+ module Cul::Hydra::Models::Aggregator
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ has_and_belongs_to_many :containers, :property=>:cul_member_of, :class_name=>'ActiveFedora::Base'
6
+ has_metadata :name => "structMetadata", :type=>Cul::Scv::Hydra::Datastreams::StructMetadata, :versionable => true, :controlGroup => 'M'
7
+ after_create :aggregator!
8
+ end
9
+
10
+ def aggregator!
11
+ add_relationship(:rdf_type, Cul::Scv::Hydra::Models::AGGREGATOR_TYPE.to_s)
12
+ @metadata_is_dirty = true
13
+ self.save
14
+ end
15
+
16
+ def add_member(member, container=self)
17
+ member.add_relationship(:cul_member_of, to_uri(container))
18
+ member.datastreams["RELS-EXT"].content_will_change!
19
+ member.save
20
+ end
21
+
22
+ def remove_member(member, container=self)
23
+ rel = ActiveFedora::Relationship.new()
24
+ rel.subject_pid= :self
25
+ rel.object = to_uri(container)
26
+ rel.predicate = :cul_member_of
27
+ member.remove_relationship(rel)
28
+ member.datastreams["RELS-EXT"].content_will_change!
29
+ member.save
30
+ end
31
+
32
+ def has_struct_metadata?
33
+ return (!datastreams['structMetadata'].nil?) && datastreams['structMetadata'].has_content?
34
+ end
35
+
36
+ def solr_members(opts={})
37
+ opts = {:rows=>25,:response_format=>:solr}.merge(opts)
38
+ r = self.parts(opts)
39
+ members = []
40
+ r.collect {|hit| members << SolrDocument.new(hit) } unless r.blank?
41
+ members
42
+ end
43
+
44
+ def members(opts={})
45
+ parts({:response_format=>:solr}.merge(opts))
46
+ end
47
+
48
+ def member_ids(opts={})
49
+ solr_members(opts).collect {|hit| hit.id}
50
+ end
51
+
52
+ def thumbnail_info
53
+ members = solr_members
54
+ if members.length == 0
55
+ thumb = {:asset=>"cul_scv_hydra/crystal/file.png",:mime=>'image/png'}
56
+ else
57
+ thumb = nil
58
+ unless datastreams['structMetadata'].new?
59
+ thumb = thumb_from_struct(members)
60
+ else
61
+ thumb = thumb_from_members(members)
62
+ end
63
+ end
64
+ return thumb || {:asset=>"cul_scv_hydra/crystal/file.png",:mime=>'image/png'}
65
+ end
66
+
67
+ private
68
+ def thumb_from_struct(members)
69
+ puts "thumb thumb_from_struct"
70
+ sm = datastreams['structMetadata']
71
+ first = sm.divs_with_attribute(false,'ORDER','1').first
72
+ if first
73
+ members.each do |member|
74
+ puts "looking for #{first["CONTENTIDS"]} in #{member["identifier_ssim"].inspect}"
75
+ if member["identifier_ssim"].include? first["CONTENTIDS"]
76
+ return thumb_from_solr_doc(member)
77
+ end
78
+ end
79
+ return thumb_from_solr_doc(members.first) if members.first
80
+ else
81
+ return nil
82
+ end
83
+ end
84
+
85
+ def thumb_from_members(members)
86
+ sorted = members.sort do |a,b|
87
+ c = a['title_si'] <=> b['title_si']
88
+ if c == 0 && a['identifier_ssim']
89
+ if b['identifier_ssim']
90
+ a['identifier_ssim'].delete(a.id) unless a['identifier_ssim'].length == 1
91
+ b['identifier_ssim'].delete(a.id) unless b['identifier_ssim'].length == 1
92
+ a['identifier_ssim'][0] <=> b['identifier_ssim'][0]
93
+ else
94
+ -1
95
+ end
96
+ else
97
+ c
98
+ end
99
+ end
100
+ thumb_from_solr_doc(sorted[0])
101
+ end
102
+
103
+ def thumb_from_solr_doc(solr_doc)
104
+ if solr_doc and (member = ActiveFedora::Base.find(solr_doc.id, :cast=>true)).respond_to? :thumbnail_info
105
+ member.thumbnail_info
106
+ else
107
+ return nil
108
+ end
109
+ end
110
+
111
+ def to_uri(obj)
112
+ if obj.respond_to? :internal_uri
113
+ return obj.internal_uri
114
+ end
115
+ obj = obj.pid unless obj.is_a? String
116
+ if obj.is_a? String and obj =~ /\A[\w\-]+:[\w\-]+\Z/
117
+ obj = "info:fedora/#{obj}"
118
+ end
119
+ return obj
120
+ end
121
+ end