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
@@ -1,20 +1,8 @@
1
- require "active-fedora"
2
- require "cul_scv_hydra/om"
3
- require 'uri'
4
- require 'rdf'
5
1
  module Cul
6
2
  module Scv
7
3
  module Hydra
8
4
  module Models
9
- AGGREGATOR_TYPE = RDF::CUL.Aggregator
10
- RESOURCE_TYPE = RDF::CUL.Resource
11
- MEMBER_OF = RDF::CUL.memberOf
12
- MEMBER_SPARQL = <<-SPARQL
13
- SELECT ?pid WHERE { ?pid <http://purl.oclc.org/NET/CUL/memberOf> <info:fedora/%PID%> }
14
- SPARQL
15
- MEMBER_ITQL = <<-ITQL
16
- select $pid from <#ri> where $pid <http://purl.oclc.org/NET/CUL/memberOf> <info:fedora/%PID%>
17
- ITQL
5
+ extend Cul::Hydra::Models
18
6
  end
19
7
  end
20
8
  end
@@ -1,121 +1,6 @@
1
1
  module Cul::Scv::Hydra::Models::Aggregator
2
2
  extend ActiveSupport::Concern
3
-
4
3
  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
4
+ include Cul::Hydra::Models::Aggregator
120
5
  end
121
6
  end
@@ -2,219 +2,7 @@ require 'active-fedora'
2
2
  require 'uri'
3
3
  module Cul::Scv::Hydra::Models::Common
4
4
  extend ActiveSupport::Concern
5
-
6
5
  included do
7
- extend ActiveModel::Callbacks
8
- define_model_callbacks :create
9
- has_metadata :name => "DC", :type=>Cul::Scv::Hydra::Datastreams::DCMetadata, :versionable => true
10
- has_metadata :name => "descMetadata", :type=>Cul::Scv::Hydra::Datastreams::ModsDocument, :versionable => true
11
- has_metadata :name => "rightsMetadata", :type=>::Hydra::Datastream::RightsMetadata, :versionable => true
12
- has_many :publishers, :property => :publisher, :class_name=>'ActiveFedora::Base'
13
- end
14
-
15
- module ClassMethods
16
- def pid_namespace
17
- 'ldpd'
18
- end
19
-
20
- end
21
-
22
- # A Fedora object label can only contain a string value of up to 255 characters. If we try to
23
- # set a longer value, it causes errors upon object save. Truncate labels to 255 characters.
24
- # Note: this method maps to a method_missing hanlder that converts input into a String, so
25
- # we use the super method first, and then post-process the output of that super method call.
26
- def label=(new_label)
27
- super(new_label)
28
- super(self.label[0,255])
29
- end
30
-
31
- def rdf_type
32
- relationships[:rdf_type]
33
- end
34
-
35
- def initialize(attrs = nil)
36
- attrs = {} if attrs.nil?
37
- attrs[:namespace] = self.class.pid_namespace unless attrs[:namespace]
38
- super
39
- end
40
-
41
- def cmodel_pid(klass)
42
- klass.pid_namespace + ":" + klass.name.split("::")[-1]
43
- end
44
-
45
- def datastreams_in_fedora
46
- mds = {}
47
- self.datastreams_xml['datastream'].each do |ds|
48
- dsid = ds["dsid"]
49
- ds.merge!({:pid => self.pid, :dsID => dsid, :dsLabel => ds["label"]})
50
- if dsid == "RELS-EXT"
51
- mds.merge!({dsid => ActiveFedora::RelsExtDatastream.new(ds)})
52
- else
53
- if self.class.ds_specs.has_key? dsid
54
- mds.merge!({dsid => self.class.ds_specs[dsid][0].new(ds)})
55
- else
56
- mds.merge!({dsid => ActiveFedora::Datastream.new(ds)})
57
- end
58
- end
59
- mds[dsid].new_object = false
60
- end
61
- mds
62
- end
63
-
64
- def route_as
65
- "default"
66
- end
67
-
68
- def has_desc?
69
- has_desc = false
70
- begin
71
- has_desc = self.datastreams.include? "descMetadata"
72
- has_desc = has_desc and self.inner_object.datastreams["descMetadata"].content.length > 0
73
- has_desc = has_desc and self.datastreams["descMetadata"].term_values(:identifier).length > 0
74
- rescue
75
- has_desc = false
76
- end
77
- has_desc
78
- end
79
-
80
- # set the index type label and any RI-based fields
81
- def set_size_labels(solr_doc={})
82
- solr_doc["index_type_label_ssi"] = [self.index_type_label]
83
- end
84
-
85
- def to_solr(solr_doc = Hash.new, opts={})
86
- solr_doc = super(solr_doc, opts)
87
-
88
- if has_desc?
89
- solr_doc["descriptor_ssi"] = ["mods"]
90
- else
91
- solr_doc["descriptor_ssi"] = ["dublin core"]
92
- end
93
- # if no mods, pull some values from DC
94
- if (solr_doc["title_display_ssm"].nil? or solr_doc["title_display_ssm"].length == 0)
95
- if self.datastreams["DC"].term_values(:dc_title).first
96
- solr_doc["title_display_ssm"] = self.datastreams["DC"].term_values(:dc_title)
97
- else
98
- solr_doc["title_display_ssm"] = self.datastreams["DC"].term_values(:dc_identifier).reject {|dcid| dcid.eql? self.id}
99
- end
100
- solr_doc["title_si"] = self.datastreams["DC"].term_values(:dc_title).first
101
- if self.datastreams["DC"].term_values(:dc_relation).first
102
- self.datastreams["DC"].term_values(:dc_relation).each {|val|
103
- if val =~ /clio:/
104
- solr_doc["clio_ssim"] ||= []
105
- solr_doc["clio_ssim"] << val.split(':')[-1]
106
- end
107
- }
108
- end
109
- end
110
- if (solr_doc["identifier_ssim"].nil? or solr_doc["identifier_ssim"].length == 0)
111
- solr_doc["identifier_ssim"] = self.datastreams["DC"].term_values(:dc_identifier).reject {|dcid| dcid.eql? self.id}
112
- end
113
- if (solr_doc["title_display_ssm"].length > 1)
114
- solr_doc["title_display_ssm"].uniq!
115
- end
116
-
117
- if solr_doc["contributor_ssim"].present?
118
- if solr_doc["contributor_ssim"].is_a?(Array)
119
- solr_doc["contributor_first_si"] = solr_doc["contributor_ssim"].first
120
- else
121
- solr_doc["contributor_first_si"] = solr_doc["contributor_ssim"]
122
- end
123
- end
124
-
125
-
126
- solr_doc["format_ssi"] = [self.route_as]
127
-
128
- set_size_labels(solr_doc)
129
-
130
- solr_doc.each_pair {|key, value|
131
- if value.is_a? Array
132
- value.each {|v| v.strip! unless v.nil? }
133
- elsif value.is_a? String
134
- value.strip!
135
- end
136
- }
137
- solr_doc[:structured_bsi] = 'false' unless solr_doc.has_key? :structured_bsi
138
-
139
- solr_doc
140
- end
141
-
142
- def update_datastream_attributes(params={}, opts={})
143
- logger.debug "Common.update_datastream_attributes"
144
- result = params.dup
145
- params.each_pair do |dsid, ds_params|
146
- if datastreams.include?(dsid)
147
- verify_params = ds_params.dup
148
- changed = false
149
- verify_params.each { |pointer, values|
150
- changed ||= value_changed?(datastreams[dsid],pointer,values)
151
- }
152
- if changed
153
- logger.debug "Common.update_datastream_attributes calling update_indexed_attributes"
154
- result[dsid] = datastreams[dsid].update_indexed_attributes(ds_params)
155
- else
156
- result[dsid] = no_update(ds_params)
157
- end
158
- logger.debug "change detected? #{changed} digital_object? #{datastreams[dsid].changed?}"
159
- else
160
- result.delete(dsid)
161
- end
162
- end
163
- return result
164
- end
165
-
166
- def thumbnail_info
167
- {:asset=>("cul_scv_hydra/crystal/kmultiple.png"),:mime_type=>"image/png"}
168
- end
169
-
170
- private
171
- def value_changed?(ds,pointer,values)
172
- if values.is_a? Hash
173
- values = values.dup
174
- else
175
- values = {"0"=>values}
176
- end
177
- logger.debug "submitted values for #{pointer.inspect} : #{values.inspect}"
178
- return true if values["-1"]
179
- changed = false
180
- old_values = ds.get_values(pointer)
181
- indexed_values = {}
182
- old_values.each_index {|ix| indexed_values[ix.to_s] = old_values[ix] }
183
- indexed_values.each {|k,v|
184
- new_val = values.delete(k)
185
- logger.debug "old: #{v} new: #{new_val} changed? #{!(v.eql? new_val)}"
186
- changed ||= !(v.eql? new_val)
187
- }
188
- logger.debug "remaining values! #{values.inspect}" if values.length > 0
189
- changed || (values.length > 0)
190
- end
191
-
192
- def no_update(ds_params)
193
- response = {}
194
- ds_params.each{|pointer, values|
195
- returned = []
196
- if values.is_a? Hash
197
- keys = values.keys.sort {|x,y| x.to_i <=> y.to_i}
198
- keys.each {|key| returned << values[key]}
199
- else
200
- returned << values
201
- end
202
- response[OM::XML::Terminology.term_hierarchical_name(pointer)] = returned
203
- }
204
- end
205
-
206
- def legacy_content_path(ds, ds_root=ActiveFedora.config.credentials[:datastreams_root])
207
- unless ds.controlGroup == 'M'
208
- return ds.dsLocation
209
- end
210
- cd = ds.dsCreateDate
211
- tz = ActiveFedora.config.credentials[:time_zone]
212
- tzi = ActiveSupport::TimeZone.find_tzinfo(tz)
213
- ld = tzi.utc_to_local(cd)
214
- month = (ld.month < 10) ? "0#{ld.month}" : ld.month.to_s
215
- day = (ld.day < 10) ? "0#{ld.day}" : ld.day.to_s
216
- hour = (ld.hour < 10) ? "0#{ld.hour}" : ld.hour.to_s
217
- min = (ld.min < 10) ? "0#{ld.min}" : ld.min.to_s
218
- return File.join(ds_root,"#{ld.year}/#{month}#{day}/#{hour}/#{min}", ds.dsLocation.sub(':','_'))
6
+ include Cul::Hydra::Models::Common
219
7
  end
220
8
  end
@@ -1,78 +1,6 @@
1
1
  module Cul::Scv::Hydra::Models::ImageResource
2
- IMAGE_EXT = {"image/bmp" => 'bmp', "image/gif" => 'gif', "image/jpeg" => 'jpg', "image/png" => 'png', "image/tiff" => 'tif', "image/x-windows-bmp" => 'bmp', 'image/jp2' => 'jp2'}
3
- WIDTH = RDF::URI(ActiveFedora::Predicates.find_graph_predicate(:image_width))
4
- LENGTH = RDF::URI(ActiveFedora::Predicates.find_graph_predicate(:image_length))
5
- WIDTH_PREDICATE = ActiveFedora::Predicates.short_predicate("http://www.w3.org/2003/12/exif/ns#imageWidth").to_s
6
- LENGTH_PREDICATE = ActiveFedora::Predicates.short_predicate("http://www.w3.org/2003/12/exif/ns#imageLength").to_s
7
- EXTENT_PREDICATE = ActiveFedora::Predicates.short_predicate("http://purl.org/dc/terms/extent").to_s
8
- FORMAT_OF_PREDICATE = ActiveFedora::Predicates.short_predicate("http://purl.org/dc/terms/isFormatOf").to_s
9
- FORMAT_URI = RDF::URI("http://purl.org/dc/terms/format")
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
- def long
25
- @long_side ||= max(width(), length())
26
- end
27
-
28
- def width
29
- @width ||= begin
30
- ds = datastreams["content"]
31
- width = 0
32
- unless ds.nil? or rels_int.relationships(ds,:exif_image_width).blank?
33
- width = rels_int.relationships(ds,:exif_image_width).first.object.to_s.to_i
34
- end
35
- width = relationships(:image_width).first.to_s.to_i if width == 0
36
- width
37
- end
38
- end
39
-
40
- def length
41
- @length ||= begin
42
- ds = datastreams["content"]
43
- length = 0
44
- unless ds.nil? or rels_int.relationships(ds,:exif_image_length).blank?
45
- length = rels_int.relationships(ds,:exif_image_length).first.object.to_s.to_i
46
- end
47
- length = relationships(:image_length).first.to_s.to_i if length == 0
48
- length
49
- end
50
- end
51
-
52
- def zooming?
53
- zoom = rels_int.relationships(datastreams['content'],:foaf_zooming).first
54
- return zoom.object.to_s if zoom
55
- datastreams.each do |k,v|
56
- if v.mimeType =~ /image\/jp2$/i
57
- zoom = "info:fedora/#{k.dsid}"
58
- end
59
- end
60
- return zoom
61
- end
62
-
63
- def thumbnail_info
64
- thumb = rels_int.relationships(datastreams['content'],:foaf_thumbnail).first
65
- if thumb
66
- t_dsid = thumb.object.to_s.split('/')[-1]
67
- t_url = "#{ActiveFedora.fedora_config.credentials[:url]}/objects/#{pid}/datastreams/#{t_dsid}/content"
68
- return {:url=>t_url,:mime=>datastreams[t_dsid].mimeType}
69
- elsif (zoom = self.zooming?)
70
- t_dsid = zoom.split('/')[-1]
71
- t_parms = DJATOKA_THUMBNAIL_PARMS.merge({"rft_id" => datastreams[t_dsid].dsLocation})
72
- url = "#{DJATOKA_BASE_URL}?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }"
73
- {:url => url, :mime => t_parms["svc.format"]}
74
- else
75
- return {:asset=>"cul_scv_hydra/crystal/file.png",:mime=>'image/png'}
76
- end
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ include Cul::Hydra::Models::ImageResource
77
5
  end
78
6
  end
@@ -1,108 +1,6 @@
1
1
  module Cul::Scv::Hydra::Models::LinkableResources
2
- include Cul::Scv::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::Scv::Fedora.repository.config[:user]
14
- pwd = Cul::Scv::Fedora.repository.config[:password]
15
- @http_client.set_auth(nil, uname, pwd)
16
- end
17
- @http_client
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ include Cul::Hydra::Models::LinkableResources
18
5
  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
6
  end