cul_hydra 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +7 -0
  2. data/app/assets/images/cul_hydra/crystal/binary.png +0 -0
  3. data/app/assets/images/cul_hydra/crystal/document.png +0 -0
  4. data/app/assets/images/cul_hydra/crystal/file.png +0 -0
  5. data/app/assets/images/cul_hydra/crystal/file_broken.png +0 -0
  6. data/app/assets/images/cul_hydra/crystal/folder_documents.png +0 -0
  7. data/app/assets/images/cul_hydra/crystal/folder_images.png +0 -0
  8. data/app/assets/images/cul_hydra/crystal/folder_music.png +0 -0
  9. data/app/assets/images/cul_hydra/crystal/folder_sound.png +0 -0
  10. data/app/assets/images/cul_hydra/crystal/folder_video.png +0 -0
  11. data/app/assets/images/cul_hydra/crystal/kmultiple.png +0 -0
  12. data/app/assets/images/cul_hydra/crystal/knotify.png +0 -0
  13. data/app/assets/images/cul_hydra/crystal/mp3.png +0 -0
  14. data/app/assets/images/cul_hydra/crystal/multimedia2.png +0 -0
  15. data/app/assets/images/cul_hydra/crystal/video.png +0 -0
  16. data/app/assets/images/cul_hydra/filesystem/application.png +0 -0
  17. data/app/assets/images/cul_hydra/filesystem/code.png +0 -0
  18. data/app/assets/images/cul_hydra/filesystem/css.png +0 -0
  19. data/app/assets/images/cul_hydra/filesystem/db.png +0 -0
  20. data/app/assets/images/cul_hydra/filesystem/directory.png +0 -0
  21. data/app/assets/images/cul_hydra/filesystem/doc.png +0 -0
  22. data/app/assets/images/cul_hydra/filesystem/file.png +0 -0
  23. data/app/assets/images/cul_hydra/filesystem/film.png +0 -0
  24. data/app/assets/images/cul_hydra/filesystem/flash.png +0 -0
  25. data/app/assets/images/cul_hydra/filesystem/folder_open.png +0 -0
  26. data/app/assets/images/cul_hydra/filesystem/html.png +0 -0
  27. data/app/assets/images/cul_hydra/filesystem/java.png +0 -0
  28. data/app/assets/images/cul_hydra/filesystem/linux.png +0 -0
  29. data/app/assets/images/cul_hydra/filesystem/music.png +0 -0
  30. data/app/assets/images/cul_hydra/filesystem/pdf.png +0 -0
  31. data/app/assets/images/cul_hydra/filesystem/php.png +0 -0
  32. data/app/assets/images/cul_hydra/filesystem/picture.png +0 -0
  33. data/app/assets/images/cul_hydra/filesystem/ppt.png +0 -0
  34. data/app/assets/images/cul_hydra/filesystem/psd.png +0 -0
  35. data/app/assets/images/cul_hydra/filesystem/ruby.png +0 -0
  36. data/app/assets/images/cul_hydra/filesystem/script.png +0 -0
  37. data/app/assets/images/cul_hydra/filesystem/spinner.gif +0 -0
  38. data/app/assets/images/cul_hydra/filesystem/txt.png +0 -0
  39. data/app/assets/images/cul_hydra/filesystem/xls.png +0 -0
  40. data/app/assets/images/cul_hydra/filesystem/zip.png +0 -0
  41. data/app/controllers/concerns/cul/hydra/application_id_behavior.rb +43 -0
  42. data/app/controllers/concerns/cul/hydra/controller.rb +22 -0
  43. data/app/controllers/concerns/cul/hydra/resolver.rb +69 -0
  44. data/app/controllers/concerns/cul/hydra/thumbnails.rb +62 -0
  45. data/app/helpers/cul/hydra/ore_proxies_helper_behavior.rb +119 -0
  46. data/app/helpers/cul/hydra/struct_metadata_helper_behavior.rb +89 -0
  47. data/app/models/bag_aggregator.rb +7 -0
  48. data/app/models/concept.rb +23 -0
  49. data/app/models/concerns/cul/hydra/models.rb +24 -0
  50. data/app/models/concerns/cul/hydra/models/aggregator.rb +121 -0
  51. data/app/models/concerns/cul/hydra/models/common.rb +220 -0
  52. data/app/models/concerns/cul/hydra/models/image_resource.rb +106 -0
  53. data/app/models/concerns/cul/hydra/models/linkable_resources.rb +108 -0
  54. data/app/models/concerns/cul/hydra/models/resource.rb +87 -0
  55. data/app/models/concerns/nfo/common.rb +17 -0
  56. data/app/models/concerns/nfo/file_data_object.rb +10 -0
  57. data/app/models/concerns/nfo/folder.rb +10 -0
  58. data/app/models/concerns/nie/information_element.rb +10 -0
  59. data/app/models/concerns/ore/proxy.rb +124 -0
  60. data/app/models/concerns/rdf/cul.rb +77 -0
  61. data/app/models/concerns/rdf/fcrepo3.rb +360 -0
  62. data/app/models/concerns/rdf/nfo.rb +807 -0
  63. data/app/models/concerns/rdf/nie.rb +338 -0
  64. data/app/models/concerns/rdf/olo.rb +100 -0
  65. data/app/models/concerns/rdf/ore.rb +101 -0
  66. data/app/models/concerns/rdf/pimo.rb +605 -0
  67. data/app/models/concerns/rdf/sc.rb +47 -0
  68. data/app/models/concerns/sc/canvas.rb +12 -0
  69. data/app/models/concerns/sc/sequence.rb +21 -0
  70. data/app/models/content_aggregator.rb +3 -0
  71. data/app/models/cul/hydra/datastreams/dc_metadata.rb +107 -0
  72. data/app/models/cul/hydra/datastreams/mods_document.rb +195 -0
  73. data/app/models/cul/hydra/datastreams/struct_metadata.rb +176 -0
  74. data/app/models/dc_document.rb +39 -0
  75. data/app/models/generic_aggregator.rb +68 -0
  76. data/app/models/generic_object.rb +18 -0
  77. data/app/models/generic_resource.rb +210 -0
  78. data/app/models/jp2_image_aggregator.rb +34 -0
  79. data/app/models/mets_structured_aggregator.rb +18 -0
  80. data/app/models/resource.rb +78 -0
  81. data/app/models/resource_aggregator.rb +22 -0
  82. data/app/models/static_audio_aggregator.rb +12 -0
  83. data/app/models/static_image_aggregator.rb +32 -0
  84. data/bin/rails +12 -0
  85. data/config/fedora.yml +17 -0
  86. data/config/jetty.yml +6 -0
  87. data/config/locales/ldpd_hydra.en.yml +125 -0
  88. data/config/predicate_mappings.yml +79 -0
  89. data/config/solr.yml +8 -0
  90. data/config/solr_mappings.yml +26 -0
  91. data/config/solr_value_maps.yml +41 -0
  92. data/config/subs.yml +17 -0
  93. data/fixtures/cmodels/ldpd_ADLMetadata.xml +56 -0
  94. data/fixtures/cmodels/ldpd_AESMetadata.xml +56 -0
  95. data/fixtures/cmodels/ldpd_BagAggregator.xml +70 -0
  96. data/fixtures/cmodels/ldpd_Concept.xml +69 -0
  97. data/fixtures/cmodels/ldpd_ContentAggregator.xml +70 -0
  98. data/fixtures/cmodels/ldpd_DynamicAggregator.xml +56 -0
  99. data/fixtures/cmodels/ldpd_JP2ImageAggregator.xml +60 -0
  100. data/fixtures/cmodels/ldpd_METSMetadata.xml +56 -0
  101. data/fixtures/cmodels/ldpd_METSStructuredAggregator.xml +53 -0
  102. data/fixtures/cmodels/ldpd_MODSMetadata.xml +73 -0
  103. data/fixtures/cmodels/ldpd_MostRecent.xml +46 -0
  104. data/fixtures/cmodels/ldpd_PTIFImageAggregator.xml +63 -0
  105. data/fixtures/cmodels/ldpd_Resource.xml +72 -0
  106. data/fixtures/cmodels/ldpd_RestrictedResource.xml +54 -0
  107. data/fixtures/cmodels/ldpd_Since.xml +62 -0
  108. data/fixtures/cmodels/ldpd_StaticAudioAggregator.xml +54 -0
  109. data/fixtures/cmodels/ldpd_StaticImageAggregator.xml +71 -0
  110. data/fixtures/cmodels/ldpd_htest.xml +54 -0
  111. data/fixtures/cmodels/ldpd_nullbind.xml +63 -0
  112. data/fixtures/cmodels/ldpd_sdef.Aggregator.xml +71 -0
  113. data/fixtures/cmodels/ldpd_sdef.Core.xml +48 -0
  114. data/fixtures/cmodels/ldpd_sdef.Image.xml +47 -0
  115. data/fixtures/cmodels/ldpd_sdef.Metadata.xml +62 -0
  116. data/fixtures/cmodels/ldpd_sdef.Resource.xml +76 -0
  117. data/fixtures/cmodels/ldpd_sdef.ZoomingImage.xml +46 -0
  118. data/fixtures/cmodels/ldpd_sdep.BagAggregator.xml +160 -0
  119. data/fixtures/cmodels/ldpd_sdep.BagAggregatorCore.xml +221 -0
  120. data/fixtures/cmodels/ldpd_sdep.ContentAggregatorCore.xml +221 -0
  121. data/fixtures/cmodels/ldpd_sdep.DynamicAggregator.xml +171 -0
  122. data/fixtures/cmodels/ldpd_sdep.DynamicAggregatorCore.xml +215 -0
  123. data/fixtures/cmodels/ldpd_sdep.JP2Image.xml +220 -0
  124. data/fixtures/cmodels/ldpd_sdep.JP2ImageAggregator.xml +167 -0
  125. data/fixtures/cmodels/ldpd_sdep.JP2ImageCore.xml +229 -0
  126. data/fixtures/cmodels/ldpd_sdep.MODSMetadata.xml +158 -0
  127. data/fixtures/cmodels/ldpd_sdep.MODSMetadataCore.xml +227 -0
  128. data/fixtures/cmodels/ldpd_sdep.PTIFImage.xml +222 -0
  129. data/fixtures/cmodels/ldpd_sdep.PTIFImageAggregator.xml +167 -0
  130. data/fixtures/cmodels/ldpd_sdep.PTIFImageCore.xml +215 -0
  131. data/fixtures/cmodels/ldpd_sdep.StaticImage.xml +210 -0
  132. data/fixtures/cmodels/ldpd_sdep.StaticImageAggregator.xml +186 -0
  133. data/fixtures/cmodels/ldpd_sdep.StaticImageCore.xml +220 -0
  134. data/fixtures/cmodels/ore_Proxy.xml +50 -0
  135. data/fixtures/spec/BLOB/test001.jpg +0 -0
  136. data/fixtures/spec/CUL_DC/dc.xml +5 -0
  137. data/fixtures/spec/CUL_MODS/mods-001.xml +25 -0
  138. data/fixtures/spec/CUL_MODS/mods-all.xml +65 -0
  139. data/fixtures/spec/CUL_MODS/mods-bad-repo.xml +7 -0
  140. data/fixtures/spec/CUL_MODS/mods-date-created-range.xml +7 -0
  141. data/fixtures/spec/CUL_MODS/mods-date-created-single.xml +6 -0
  142. data/fixtures/spec/CUL_MODS/mods-date-end-with-all-u-characters.xml +7 -0
  143. data/fixtures/spec/CUL_MODS/mods-date-issued-range.xml +7 -0
  144. data/fixtures/spec/CUL_MODS/mods-date-issued-single.xml +6 -0
  145. data/fixtures/spec/CUL_MODS/mods-date-other-range.xml +7 -0
  146. data/fixtures/spec/CUL_MODS/mods-date-other-single.xml +6 -0
  147. data/fixtures/spec/CUL_MODS/mods-date-range-short-years.xml +7 -0
  148. data/fixtures/spec/CUL_MODS/mods-date-start-with-all-u-characters.xml +7 -0
  149. data/fixtures/spec/CUL_MODS/mods-dates-with-all-u-characters.xml +7 -0
  150. data/fixtures/spec/CUL_MODS/mods-dates-with-some-u-characters.xml +7 -0
  151. data/fixtures/spec/CUL_MODS/mods-item.xml +31 -0
  152. data/fixtures/spec/CUL_MODS/mods-names.xml +35 -0
  153. data/fixtures/spec/CUL_MODS/mods-notes.xml +8 -0
  154. data/fixtures/spec/CUL_MODS/mods-ns.xml +2 -0
  155. data/fixtures/spec/CUL_MODS/mods-origin-info.xml +9 -0
  156. data/fixtures/spec/CUL_MODS/mods-part.xml +22 -0
  157. data/fixtures/spec/CUL_MODS/mods-physical-description.xml +12 -0
  158. data/fixtures/spec/CUL_MODS/mods-physical-location.xml +9 -0
  159. data/fixtures/spec/CUL_MODS/mods-record-info.xml +4 -0
  160. data/fixtures/spec/CUL_MODS/mods-relateditem-project.xml +8 -0
  161. data/fixtures/spec/CUL_MODS/mods-subjects.xml +73 -0
  162. data/fixtures/spec/CUL_MODS/mods-textual-date.xml +8 -0
  163. data/fixtures/spec/CUL_MODS/mods-titles.xml +33 -0
  164. data/fixtures/spec/CUL_MODS/mods-top-level-location-vs-relateditem-location.xml +21 -0
  165. data/fixtures/spec/CUL_MODS/mods-unmapped-project.xml +7 -0
  166. data/fixtures/spec/CUL_SOLR/mods-001.xml +1 -0
  167. data/fixtures/spec/CUL_SOLR/mods-001.yml +30 -0
  168. data/fixtures/spec/FOXML/content-aggregator.xml +64 -0
  169. data/fixtures/spec/FOXML/content-cmodel.xml +48 -0
  170. data/fixtures/spec/FOXML/image-cmodel.xml +48 -0
  171. data/fixtures/spec/FOXML/resource-max.xml +83 -0
  172. data/fixtures/spec/FOXML/resource-screen.xml +273 -0
  173. data/fixtures/spec/FOXML/resource-thumb.xml +86 -0
  174. data/fixtures/spec/FOXML/static-image-aggregator.xml +31 -0
  175. data/fixtures/spec/STRUCTMAP/structmap-examples.xml +21 -0
  176. data/fixtures/spec/STRUCTMAP/structmap-nested.xml +10 -0
  177. data/fixtures/spec/STRUCTMAP/structmap-recto.xml +4 -0
  178. data/fixtures/spec/STRUCTMAP/structmap-seq.xml +5 -0
  179. data/fixtures/spec/STRUCTMAP/structmap-unordered-seq.xml +5 -0
  180. data/lib/cul_hydra.rb +20 -0
  181. data/lib/cul_hydra/access_controls_enforcement.rb +53 -0
  182. data/lib/cul_hydra/controllers.rb +13 -0
  183. data/lib/cul_hydra/controllers/aggregates.rb +93 -0
  184. data/lib/cul_hydra/controllers/aggregator_controller_helper.rb +27 -0
  185. data/lib/cul_hydra/controllers/catalog.rb +12 -0
  186. data/lib/cul_hydra/controllers/content_aggregators.rb +81 -0
  187. data/lib/cul_hydra/controllers/datastreams.rb +145 -0
  188. data/lib/cul_hydra/controllers/helpers.rb +10 -0
  189. data/lib/cul_hydra/controllers/helpers/active_fedora_helper_behavior.rb +9 -0
  190. data/lib/cul_hydra/controllers/helpers/application_helper_behavior.rb +16 -0
  191. data/lib/cul_hydra/controllers/helpers/dc_metadata_helper_behavior.rb +9 -0
  192. data/lib/cul_hydra/controllers/helpers/hydra_assets_helper_behavior.rb +46 -0
  193. data/lib/cul_hydra/controllers/helpers/hydra_autocomplete_helper_behavior.rb +35 -0
  194. data/lib/cul_hydra/controllers/helpers/hydra_uploader_helper_behavior.rb +34 -0
  195. data/lib/cul_hydra/controllers/helpers/resources_helper_behavior.rb +159 -0
  196. data/lib/cul_hydra/controllers/resources.rb +161 -0
  197. data/lib/cul_hydra/controllers/static_image_aggregators.rb +105 -0
  198. data/lib/cul_hydra/controllers/suggestions.rb +126 -0
  199. data/lib/cul_hydra/controllers/terms.rb +205 -0
  200. data/lib/cul_hydra/engine.rb +31 -0
  201. data/lib/cul_hydra/fedora.rb +41 -0
  202. data/lib/cul_hydra/fedora/dummy_object.rb +37 -0
  203. data/lib/cul_hydra/fedora/rubydora_patch.rb +16 -0
  204. data/lib/cul_hydra/fedora/url_helper_behavior.rb +32 -0
  205. data/lib/cul_hydra/indexer.rb +102 -0
  206. data/lib/cul_hydra/om.rb +7 -0
  207. data/lib/cul_hydra/om/standard_mods.rb +115 -0
  208. data/lib/cul_hydra/risearch_members.rb +92 -0
  209. data/lib/cul_hydra/solrizer.rb +10 -0
  210. data/lib/cul_hydra/solrizer/extractor.rb +27 -0
  211. data/lib/cul_hydra/solrizer/mods_fieldable.rb +473 -0
  212. data/lib/cul_hydra/solrizer/terminology_based_solrizer.rb +35 -0
  213. data/lib/cul_hydra/solrizer/value_mapper.rb +46 -0
  214. data/lib/cul_hydra/solrizer_patch.rb +172 -0
  215. data/lib/cul_hydra/version.rb +8 -0
  216. data/lib/cul_hydra/version.rb~ +8 -0
  217. data/lib/tasks/cmodel.rake +122 -0
  218. data/lib/tasks/cul_hydra_dev.rake +54 -0
  219. data/lib/tasks/index.rake +73 -0
  220. data/lib/tasks/transform.rake +23 -0
  221. metadata +503 -0
@@ -0,0 +1,39 @@
1
+ require "active-fedora"
2
+ require "active_fedora_finders"
3
+ class DcDocument < ActiveFedora::Base
4
+ include ::ActiveFedora::Associations
5
+ include ::ActiveFedora::FinderMethods::RepositoryMethods
6
+ include ::ActiveFedora::DatastreamCollections
7
+ include Hydra::ModelMethods
8
+ include Cul::Hydra::Models::Common
9
+ #alias :file_objects :resources
10
+
11
+ has_and_belongs_to_many :parts, :property => :cul_member_of, :class_name=>'ActiveFedora::Base'
12
+
13
+ def self.load_instance_from_solr(pid,solr_doc=nil)
14
+ if solr_doc.nil?
15
+ result = find_by_solr(pid)
16
+ raise "Object #{pid} not found in solr" if result.nil?
17
+ solr_doc = result.hits.first
18
+ #double check pid and id in record match
19
+ raise "Object #{pid} not found in Solr" unless !result.nil? && !solr_doc.nil? && pid == solr_doc[SOLR_DOCUMENT_ID]
20
+ else
21
+ raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
22
+ end
23
+
24
+ create_date = solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date).to_s] : solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date)]
25
+ modified_date = solr_doc[::ActiveFedora::SolrService.solr_name(:system_create, :date)].nil? ? solr_doc[::ActiveFedora::SolrService.solr_name(:system_modified, :date).to_s] : solr_doc[::ActiveFedora::SolrService.solr_name(:system_modified, :date)]
26
+ obj = DcDocument.new({:pid=>solr_doc[SOLR_DOCUMENT_ID],:create_date=>create_date,:modified_date=>modified_date})
27
+ obj.new_object = false
28
+ #set by default to load any dependent relationship objects from solr as well
29
+ obj.load_from_solr = true
30
+ #need to call rels_ext once so it exists when iterating over datastreams
31
+ obj.rels_ext
32
+ obj.datastreams.each_value do |ds|
33
+ if ds.respond_to?(:from_solr)
34
+ ds.from_solr(solr_doc) if ds.kind_of?(::ActiveFedora::MetadataDatastream) || ds.kind_of?(::ActiveFedora::NokogiriDatastream) || ( ds.kind_of?(::ActiveFedora::RelsExtDatastream))
35
+ end
36
+ end
37
+ obj
38
+ end
39
+ end
@@ -0,0 +1,68 @@
1
+ require "active-fedora"
2
+ require "active_fedora_finders"
3
+ class GenericAggregator < ::ActiveFedora::Base
4
+ include ::ActiveFedora::FinderMethods::RepositoryMethods
5
+ include ::ActiveFedora::DatastreamCollections
6
+ include Hydra::ModelMethods
7
+ include Cul::Hydra::Models::Common
8
+ include Cul::Hydra::Models::Aggregator
9
+
10
+ has_many :parts, :property => :cul_member_of, :class_name=>'ActiveFedora::Base'
11
+
12
+ def route_as
13
+ "multipartitem"
14
+ end
15
+
16
+ def index_type_label
17
+ riquery = Cul::Hydra::Models::MEMBER_ITQL.gsub(/%PID%/, self.pid)
18
+ begin
19
+ docs = Cul::Hydra::Fedora.repository.find_by_itql riquery, limit: 2, format: 'count/json'
20
+ docs = JSON.parse(docs)['results']
21
+ size = docs.first && docs.first['count'] && docs.first['count'].to_i
22
+ rescue Exception=>e
23
+ Rails.logger.warn("#{self.class.name} failed to find children with TQL: #{e.message}")
24
+ end
25
+ size ||= self.parts(response_format: :solr, limit: 2).size
26
+ type_label_for(size)
27
+ end
28
+
29
+ def type_label_for(size=nil)
30
+ if size == 0
31
+ return "EMPTY"
32
+ elsif size == 1
33
+ return "SINGLE PART"
34
+ else
35
+ return "MULTIPART"
36
+ end
37
+ end
38
+
39
+ # set the index type label and any RI-based fields
40
+ # overridde
41
+ def set_size_labels(solr_doc={})
42
+ count = Cul::Hydra::RisearchMembers.get_direct_member_count(pid)
43
+ solr_doc["index_type_label_ssi"] = [type_label_for(count)]
44
+ solr_doc["cul_number_of_members_isi"] = count
45
+ end
46
+
47
+ def to_solr(solr_doc = Hash.new, opts={})
48
+ solr_doc = super(solr_doc, opts)
49
+ solr_doc
50
+ end
51
+
52
+ def proxies
53
+ datastreams['structMetadata'] ? datastreams['structMetadata'].proxies : []
54
+ end
55
+ def update_index
56
+ super
57
+ if has_struct_metadata?()
58
+ conn = ActiveFedora::SolrService.instance.conn
59
+ # delete by query proxyIn_ssi: internal_uri
60
+ conn.delete_by_query("proxyIn_ssi:#{RSolr.escape(internal_uri())}")
61
+
62
+ # reindex proxies
63
+ proxy_docs = proxies().collect {|p| p.to_solr}
64
+ conn.add(proxy_docs, params: {softCommit: true})
65
+ conn.commit
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,18 @@
1
+ require "active-fedora"
2
+ require "active_fedora_finders"
3
+ class GenericObject < ::ActiveFedora::Base
4
+ extend ActiveModel::Callbacks
5
+ include ::ActiveFedora::FinderMethods::RepositoryMethods
6
+ include ::ActiveFedora::DatastreamCollections
7
+ include ::Hydra::ModelMethods
8
+ include Cul::Hydra::Models::Common
9
+ include Cul::Hydra::Models::Aggregator
10
+
11
+ has_many :parts, :property => :cul_member_of, :class_name=>'ActiveFedora::Base'
12
+
13
+ #alias :file_objects :resources
14
+
15
+ def route_as
16
+ "multipartitem"
17
+ end
18
+ end
@@ -0,0 +1,210 @@
1
+ require "cul_image_props"
2
+ require "mime/types"
3
+ require "uri"
4
+ require "open-uri"
5
+ require "tempfile"
6
+ require "active_fedora_finders"
7
+ class GenericResource < ::ActiveFedora::Base
8
+ extend ActiveModel::Callbacks
9
+ include ::ActiveFedora::FinderMethods::RepositoryMethods
10
+ include ::ActiveFedora::DatastreamCollections
11
+ include ::Hydra::ModelMethods
12
+ include Cul::Hydra::Models::Common
13
+ include Cul::Hydra::Models::ImageResource
14
+ include Cul::Hydra::Fedora::UrlHelperBehavior
15
+ include ::ActiveFedora::RelsInt
16
+
17
+ has_and_belongs_to_many :containers, :property=>:cul_member_of, :class_name=>'ActiveFedora::Base'
18
+
19
+ IMAGE_EXT = {"image/bmp" => 'bmp', "image/gif" => 'gif', "image/jpeg" => 'jpg', "image/png" => 'png', "image/tiff" => 'tif', "image/x-windows-bmp" => 'bmp'}
20
+ WIDTH = RDF::URI(ActiveFedora::Predicates.find_graph_predicate(:image_width))
21
+ LENGTH = RDF::URI(ActiveFedora::Predicates.find_graph_predicate(:image_length))
22
+
23
+ has_datastream :name => "content", :type=>::ActiveFedora::Datastream, :versionable => true
24
+ has_metadata :name=>"RELS-INT", :type=>ActiveFedora::RelsInt::Datastream
25
+
26
+ def assert_content_model
27
+ super
28
+ add_relationship(:rdf_type, RDF::CUL.Resource.to_s)
29
+ end
30
+
31
+ def route_as
32
+ "resource"
33
+ end
34
+
35
+ def index_type_label
36
+ "FILE ASSET"
37
+ end
38
+
39
+ def thumbnail_info
40
+ thumb = relsint.relationships(datastreams['content'],:foaf_thumb).first
41
+ if thumb
42
+ t_dsid = thumb.object.to_s.split('/')[-1]
43
+ return {:url=>"#{ActiveFedora.fedora_config[:url]}/objects/#{pid}/datastreams/#{t_dsid}/content",:mime=>datastreams[t_dsid].mimeType}
44
+ else
45
+ return {:url=>image_url("cul_hydra/crystal/file.png"),:mime=>'image/png'}
46
+ end
47
+ end
48
+
49
+ def to_solr(solr_doc = Hash.new, opts={})
50
+ solr_doc = super
51
+
52
+ unless solr_doc["extent_ssim"] || self.datastreams["content"].nil?
53
+ if self.datastreams["content"].dsSize.to_i > 0
54
+ solr_doc["extent_ssim"] = [self.datastreams["content"].dsSize]
55
+ else
56
+ repo = ActiveFedora::Base.connection_for_pid(pid)
57
+ ds_parms = {pid: pid, dsid: "content", method: :head}
58
+ repo.datastream_dissemination(ds_parms) do |res|
59
+ solr_doc["extent_ssim"] = res['Content-Length']
60
+ end
61
+ end
62
+ end
63
+
64
+ if self.zooming?
65
+ fz = rels_int.relationships(datastreams['content'], :foaf_zooming).first.object.to_s.split('/')[-1]
66
+ ds = datastreams[fz]
67
+ unless ds.nil?
68
+ rft_id = ds.controlGroup == 'E' ? datastreams[fz].dsLocation : legacy_content_path(ds,'info:fedora/datastreams/')
69
+ solr_doc['rft_id_ss'] = rft_id
70
+ end
71
+ end
72
+
73
+ solr_doc["fulltext_tesim"] = []
74
+ unless self.datastreams["fulltext"].nil?
75
+ solr_doc["fulltext_tesim"].concat(solr_doc["title_display_ssm"]) unless solr_doc["title_display_ssm"].nil? or solr_doc["title_display_ssm"].length == 0
76
+ solr_doc["fulltext_tesim"] << self.datastreams["fulltext"].content
77
+ end
78
+ relationships(:original_name).each do |original_name|
79
+ solr_doc["original_name_tesim"] ||= []
80
+ original_name = original_name.object.to_s.split('/').join(' ')
81
+ solr_doc["original_name_tesim"] << original_name.strip
82
+ end
83
+
84
+ solr_doc
85
+ end
86
+
87
+ def thumbnail_info
88
+ thumb = rels_int.relationships(datastreams['content'],:foaf_thumbnail).first
89
+ if thumb
90
+ t_dsid = thumb.object.to_s.split('/')[-1]
91
+ t_url = "#{ActiveFedora.fedora_config.credentials[:url]}/objects/#{pid}/datastreams/#{t_dsid}/content"
92
+ return {:url=>t_url,:mime=>datastreams[t_dsid].mimeType}
93
+ elsif self.zooming?
94
+ t_dsid = rels_int.relationships(dsuri, :foaf_zooming).first.object.to_s.split('/')[-1]
95
+ t_parms = DJATOKA_THUMBNAIL_PARMS.merge({"rft_id" => datastreams[t_dsid].dsLocation})
96
+ url = "#{DJATOKA_BASE_URL}?#{options.map { |key, value| "#{CGI::escape(key.to_s)}=#{CGI::escape(value.to_s)}"}.join("&") }"
97
+ {:url => url, :mime => t_parms["svc.format"]}
98
+ else
99
+ return {:asset => "cul_hydra/crystal/file.png",:mime=>'image/png'}
100
+ end
101
+ end
102
+
103
+ def linkable_resources
104
+ # let's start with the known DSIDs from lindquist, then work our way back to parsing the solrized relsint
105
+ results = []
106
+ if (rels = rels_int.instance_variable_get :@solr_hash)
107
+ # this was loaded from solr
108
+ rels.each do |dsuri, props|
109
+ if dsuri =~ /\/content$/ or not props[FORMAT_OF_PREDICATE].blank?
110
+ dsid = dsuri.split('/')[-1]
111
+ puts props.inspect
112
+ res = datastream_as_resource(dsid, props.with_indifferent_access)
113
+ results << res
114
+ end
115
+ end
116
+ else
117
+ content_uri = RDF::URI("info:fedora/#{self.pid}/content")
118
+ dsuris = [content_uri]
119
+ results = []
120
+ # read the graph
121
+ datastreams.each do |k, v|
122
+ rels = rels_int.relationships(v, :format_of, content_uri)
123
+ dsuris << rels[0].subject unless rels.blank?
124
+ end
125
+
126
+ dsuris.each do |dsuri|
127
+ dsid = dsuri.to_s.split('/')[-1]
128
+ width_rel = rels_int.relationships(dsuri, :image_width)[0]
129
+ length_rel = rels_int.relationships(dsuri, :image_length)[0]
130
+ extent_rel = rels_int.relationships(dsuri, :extent)[0]
131
+ props = {extent: [], image_width: [], image_length: []}
132
+ props[:extent] << extent_rel.object.to_s unless extent_rel.blank?
133
+ props[:image_width] << width_rel.object.to_s unless width_rel.blank?
134
+ props[:image_length] << length_rel.object.to_s unless length_rel.blank?
135
+ results << datastream_as_resource(dsid, props)
136
+ end
137
+ end
138
+ results
139
+ end
140
+
141
+ def zooming?
142
+ (zr = rels_int.relationships(datastreams['content'], :foaf_zooming) and not zr.first.blank?)
143
+ end
144
+
145
+ def with_ds_resource(ds_id, fedora_content_filesystem_mounted=false, &block)
146
+
147
+ ds = self.datastreams[ds_id]
148
+
149
+ puts 'dsLocation.start_with?(self.pid) : ' + ds.dsLocation.start_with?(self.pid).to_s
150
+
151
+ # If the dsLocation starts with the pid, that means that we're dealing with an internally-managed ds,
152
+ # so we can't reference the file directly even if we do have the fedora content filesystem mounted.
153
+ if ! ds.dsLocation.start_with?(self.pid) && fedora_content_filesystem_mounted
154
+ if ds.dsLocation =~ /^file:\//
155
+ dsLocation = ds.dsLocation.sub(/^file:\/+/,'/')
156
+ path = URI.unescape(dsLocation)
157
+ else
158
+ path = ds.dsLocation
159
+ end
160
+
161
+ yield(path)
162
+ else
163
+ internal_uri = "info:fedora/#{self.pid}/#{ds_id}"
164
+ # No local fedora mount, need to download content over http[s]
165
+
166
+ file_basename = File.basename(ds.dsLocation.gsub(/^file:/,''))
167
+ file_extension = File.extname(file_basename)
168
+
169
+ # In some cases, we actually do want to know the original extension of the file, so we'll preserve it in the temp file filename
170
+ temp_file = Tempfile.new([file_basename, file_extension])
171
+ begin
172
+ parts = internal_uri.split('/')
173
+ open(temp_file.path, 'wb') do |blob|
174
+ repo = ActiveFedora::Base.connection_for_pid(parts[1])
175
+ repo.datastream_dissemination({:dsid=>parts[2], :pid=>parts[1], :finished=>false}) do |res|
176
+ res.read_body do |seg|
177
+ blob << seg
178
+ end
179
+ end
180
+ end
181
+ yield(temp_file.path)
182
+ ensure
183
+ temp_file.unlink
184
+ end
185
+ end
186
+
187
+ end
188
+
189
+ private
190
+ def datastream_as_resource(dsid, props={})
191
+ ds = datastreams[dsid]
192
+ raise "No resource at info:fedora/#{pid}/#{dsid}" unless ds
193
+ res = {}
194
+ res[:uri] = self.pid
195
+ res[:block] = dsid
196
+ res[:mime_type] = ds.mimeType
197
+ res[:content_models] = ["Datastream"]
198
+ res[:file_size] = ds.dsSize.to_s
199
+ if res[:file_size] == "0" and props[:extent]
200
+ res[:file_size] = (props[:extent].first || "0")
201
+ end
202
+ res[:size] = (res[:file_size].to_i / 1024).to_s + " Kb"
203
+ res[:width] = (props[:image_width] and props[:image_width].first) || "0"
204
+ res[:height] = (props[:image_length] and props[:image_length].first) || "0"
205
+ res[:dimensions] = "#{res[:width]} x #{res[:height]}"
206
+ base_filename = pid.gsub(/\:/,"")
207
+ res[:filename] = base_filename + "." + dsid + "." + ds.mimeType.gsub(/^[^\/]+\//,"")
208
+ res
209
+ end
210
+ end
@@ -0,0 +1,34 @@
1
+ require "active-fedora"
2
+ require "active_fedora_finders"
3
+ class JP2ImageAggregator < ResourceAggregator
4
+
5
+ has_datastream :name => "SOURCE", :type=>::ActiveFedora::Datastream, :mimeType=>"image/jp2", :controlGroup=>'E'
6
+
7
+ def route_as
8
+ "zoomingimage"
9
+ end
10
+
11
+ def index_type_label
12
+ "PART"
13
+ end
14
+
15
+ def to_solr(solr_doc = Hash.new, opts={})
16
+ solr_doc = super
17
+ source = self.datastreams["SOURCE"]
18
+ source.profile
19
+ if source.controlGroup == 'E'
20
+ solr_doc["rft_id_ss"] = source.dsLocation
21
+ else
22
+ rc = ActiveFedora::RubydoraConnection.instance.connection
23
+ url = rc.config["url"]
24
+ uri = URI::parse(url)
25
+ url = "#{uri.scheme}://#{uri.host}:#{uri.port}/fedora/objects/#{pid}/datastreams/SOURCE/content"
26
+ solr_doc["rft_id_ss"] = url
27
+ end
28
+ solr_doc
29
+ end
30
+
31
+ def thumbnail_info
32
+ {:url => "#{ActiveFedora.fedora_config[:url]}/objects/#{pid}/methods/ldpd:sdef.Image/getView?max=250", :mime => 'image/jpeg'}
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ require "active-fedora"
2
+ require "active_fedora_finders"
3
+ class METSStructuredAggregator < ::ActiveFedora::Base
4
+ extend ActiveModel::Callbacks
5
+ include ::ActiveFedora::FinderMethods::RepositoryMethods
6
+ include ::ActiveFedora::DatastreamCollections
7
+ include ::Hydra::ModelMethods
8
+ include Cul::Hydra::Models::Common
9
+ include Cul::Hydra::Models::Aggregator
10
+
11
+ has_many :parts, :property => :cul_member_of, :class_name=>'ActiveFedora::Base'
12
+
13
+ #alias :file_objects :resources
14
+
15
+ def route_as
16
+ "multipartitem"
17
+ end
18
+ end
@@ -0,0 +1,78 @@
1
+ require "active-fedora"
2
+ require "active_fedora_finders"
3
+ require "cul_image_props"
4
+ require "mime/types"
5
+ require "uri"
6
+ class Resource < ActiveFedora::Base
7
+ include ::ActiveFedora::FinderMethods::RepositoryMethods
8
+ include ::ActiveFedora::DatastreamCollections
9
+ # include ::Hydra::ModelMethods
10
+ include Cul::Hydra::Models::Common
11
+ include Cul::Hydra::Models::Resource
12
+ include Cul::Hydra::Models::ImageResource
13
+
14
+ belongs_to :container, :property=>:cul_member_of, :class_name=>'ActiveFedora::Base'
15
+
16
+ # CUL_WIDTH = "http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/BASIC/imageWidth"
17
+ # CUL_LENGTH = "http://purl.oclc.org/NET/CUL/RESOURCE/STILLIMAGE/BASIC/imageLength"
18
+ # FORMAT = "http://purl.org/dc/elements/1.1/format"
19
+ # MEMBER_OF = "http://purl.oclc.org/NET/CUL/memberOf"
20
+
21
+ def route_as
22
+ "resource"
23
+ end
24
+
25
+ def index_type_label
26
+ "FILE RESOURCE"
27
+ end
28
+
29
+ def to_solr(solr_doc = Hash.new, opts={})
30
+ super
31
+ unless solr_doc["extent_ssi"] || self.datastreams["CONTENT"].nil?
32
+ solr_doc["extent_ssi"] = [self.datastreams["CONTENT"].size]
33
+ end
34
+ solr_doc
35
+ end
36
+
37
+ def set_title_and_label(new_title, opts={})
38
+ if opts[:only_if_blank]
39
+ if self.label.nil? || self.label.empty?
40
+ self.label = new_title
41
+ self.set_title( new_title )
42
+ end
43
+ else
44
+ self.label = new_title
45
+ set_title( new_title )
46
+ end
47
+ end
48
+
49
+ # Set the title and label on the current object
50
+ #
51
+ # @param [String] new_title
52
+ # @param [Hash] opts (optional) hash of configuration options
53
+ def set_title(new_title, opts={})
54
+ if has_desc?
55
+ desc_metadata_ds = self.datastreams["descMetadata"]
56
+ if desc_metadata_ds.respond_to?(:title_values)
57
+ desc_metadata_ds.title_values = new_title
58
+ else
59
+ desc_metadata_ds.title = new_title
60
+ end
61
+ end
62
+ end
63
+
64
+ def thumbnail_info
65
+ # do the triples indicate this is a thumb? fetch
66
+ if long <= 251
67
+ mime = object_relations[FORMAT].first
68
+ url = {:url=>"#{ActiveFedora.fedora_config[:url]}/objects/#{self.pid}/datastreams/CONTENT/content", :mime=>mime}
69
+ else
70
+ if object_relations[MEMBER_OF].blank?
71
+ return {:url=>image_url("cul_hydra/crystal/file.png"),:mime=>'image/png'}
72
+ else
73
+ url = ActiveFedora::Base.find(parents.first, :cast => true).thumbnail_info
74
+ end
75
+ end
76
+ return url
77
+ end
78
+ end