ddr-models 2.11.0 → 3.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +7 -6
  4. data/Gemfile +2 -3
  5. data/Rakefile +5 -5
  6. data/app/controllers/users/sessions_controller.rb +5 -0
  7. data/app/helpers/models_helper.rb +7 -0
  8. data/app/models/attachment.rb +3 -5
  9. data/app/models/collection.rb +12 -79
  10. data/app/models/component.rb +8 -67
  11. data/app/models/item.rb +8 -73
  12. data/app/models/target.rb +6 -5
  13. data/config/initializers/active_fedora_base.rb +11 -30
  14. data/config/initializers/{active_fedora_datastream.rb → active_fedora_file.rb} +1 -1
  15. data/config/initializers/devise.rb +2 -3
  16. data/config/initializers/subscriptions.rb +2 -19
  17. data/ddr-models.gemspec +10 -14
  18. data/lib/ddr/actions/fixity_check.rb +1 -1
  19. data/lib/ddr/actions/virus_check.rb +17 -10
  20. data/lib/ddr/auth.rb +6 -38
  21. data/lib/ddr/auth/ability.rb +1 -5
  22. data/lib/ddr/auth/ability_definitions/collection_ability_definitions.rb +0 -16
  23. data/lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb +10 -4
  24. data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +16 -9
  25. data/lib/ddr/auth/ability_factory.rb +25 -2
  26. data/lib/ddr/auth/abstract_ability.rb +1 -2
  27. data/lib/ddr/auth/auth_context.rb +0 -18
  28. data/lib/ddr/auth/auth_context_factory.rb +2 -0
  29. data/lib/ddr/auth/group.rb +0 -6
  30. data/lib/ddr/auth/grouper_gateway.rb +0 -24
  31. data/lib/ddr/auth/permissions.rb +1 -12
  32. data/lib/ddr/auth/role_based_access_controls_enforcement.rb +5 -5
  33. data/lib/ddr/auth/roles.rb +1 -11
  34. data/lib/ddr/auth/roles/role_set.rb +0 -7
  35. data/lib/ddr/auth/roles/roles_datastream.rb +9 -0
  36. data/lib/ddr/contacts.rb +25 -0
  37. data/lib/ddr/datastreams.rb +10 -28
  38. data/lib/ddr/datastreams/datastream_behavior.rb +30 -100
  39. data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +28 -31
  40. data/lib/ddr/datastreams/fits_datastream.rb +9 -22
  41. data/lib/ddr/datastreams/metadata_datastream.rb +17 -31
  42. data/lib/ddr/derivatives.rb +13 -16
  43. data/lib/ddr/derivatives/derivative.rb +68 -0
  44. data/lib/ddr/derivatives/{generator.rb → generators/generator.rb} +11 -7
  45. data/lib/ddr/derivatives/generators/png_generator.rb +23 -0
  46. data/lib/ddr/derivatives/generators/ptif_generator.rb +56 -0
  47. data/lib/ddr/derivatives/multires_image.rb +59 -0
  48. data/lib/ddr/derivatives/thumbnail.rb +36 -0
  49. data/lib/ddr/events.rb +0 -1
  50. data/lib/ddr/events/deletion_event.rb +9 -5
  51. data/lib/ddr/events/event.rb +8 -13
  52. data/lib/ddr/events/fixity_check_event.rb +0 -6
  53. data/lib/ddr/events/ingestion_event.rb +9 -5
  54. data/lib/ddr/events/update_event.rb +4 -17
  55. data/lib/ddr/index.rb +4 -4
  56. data/lib/ddr/index/abstract_query_result.rb +4 -3
  57. data/lib/ddr/index/connection.rb +9 -28
  58. data/lib/ddr/index/csv_query_result.rb +32 -47
  59. data/lib/ddr/index/field.rb +1 -11
  60. data/lib/ddr/index/fields.rb +16 -99
  61. data/lib/ddr/index/filter.rb +30 -103
  62. data/lib/ddr/index/filters.rb +19 -0
  63. data/lib/ddr/index/query.rb +11 -58
  64. data/lib/ddr/index/query_builder.rb +36 -147
  65. data/lib/ddr/index/query_clause.rb +19 -79
  66. data/lib/ddr/index/query_result.rb +4 -36
  67. data/lib/ddr/index/query_value.rb +18 -0
  68. data/lib/ddr/index/response.rb +2 -19
  69. data/lib/ddr/jobs.rb +12 -0
  70. data/lib/ddr/jobs/fits_file_characterization.rb +51 -0
  71. data/lib/ddr/jobs/permanent_id.rb +23 -0
  72. data/lib/ddr/managers.rb +1 -0
  73. data/lib/ddr/managers/derivatives_manager.rb +53 -93
  74. data/lib/ddr/managers/permanent_id_manager.rb +91 -0
  75. data/lib/ddr/managers/technical_metadata_manager.rb +10 -24
  76. data/lib/ddr/managers/workflow_manager.rb +10 -29
  77. data/lib/ddr/models.rb +50 -101
  78. data/lib/ddr/models/access_controllable.rb +12 -0
  79. data/lib/ddr/models/admin_set.rb +5 -16
  80. data/lib/ddr/models/base.rb +45 -165
  81. data/lib/ddr/models/describable.rb +19 -21
  82. data/lib/ddr/models/engine.rb +11 -39
  83. data/lib/ddr/models/error.rb +0 -3
  84. data/lib/ddr/models/file_management.rb +36 -72
  85. data/lib/ddr/models/finding_aid.rb +2 -35
  86. data/lib/ddr/models/fixity_checkable.rb +4 -0
  87. data/lib/ddr/models/governable.rb +3 -1
  88. data/lib/ddr/models/has_admin_metadata.rb +82 -56
  89. data/lib/ddr/models/has_attachments.rb +3 -1
  90. data/lib/ddr/models/has_children.rb +3 -7
  91. data/lib/ddr/models/has_content.rb +35 -32
  92. data/lib/ddr/models/has_multires_image.rb +7 -12
  93. data/lib/ddr/models/has_struct_metadata.rb +44 -6
  94. data/lib/ddr/models/has_thumbnail.rb +1 -4
  95. data/lib/ddr/models/indexing.rb +97 -186
  96. data/lib/ddr/models/licenses/admin_policy_license.rb +11 -0
  97. data/lib/ddr/models/licenses/effective_license.rb +9 -0
  98. data/lib/ddr/models/licenses/inherited_license.rb +9 -0
  99. data/lib/ddr/models/licenses/license.rb +21 -0
  100. data/lib/ddr/models/licenses/parent_license.rb +11 -0
  101. data/lib/ddr/models/metadata/descriptive_metadata.rb +50 -0
  102. data/lib/ddr/models/metadata/metadata.rb +37 -0
  103. data/lib/ddr/models/metadata/metadata_mapper.rb +32 -0
  104. data/lib/ddr/models/metadata/metadata_mappers.rb +18 -0
  105. data/lib/ddr/models/metadata/metadata_term.rb +24 -0
  106. data/lib/ddr/models/metadata/metadata_vocabularies.rb +18 -0
  107. data/lib/ddr/models/metadata/metadata_vocabulary.rb +34 -0
  108. data/lib/ddr/models/solr_document.rb +24 -156
  109. data/lib/ddr/models/struct_div.rb +63 -0
  110. data/lib/ddr/models/structure.rb +39 -175
  111. data/lib/ddr/models/version.rb +1 -1
  112. data/lib/ddr/models/year_facet.rb +118 -60
  113. data/lib/ddr/notifications.rb +12 -10
  114. data/lib/ddr/utils.rb +15 -28
  115. data/lib/ddr/vocab.rb +17 -15
  116. data/lib/ddr/vocab/asset.rb +17 -42
  117. data/lib/ddr/vocab/contact.rb +7 -5
  118. data/lib/ddr/vocab/display.rb +8 -6
  119. data/lib/ddr/vocab/duke_terms.rb +10 -8
  120. data/lib/ddr/vocab/rdf_vocabulary_parser.rb +39 -37
  121. data/lib/ddr/vocab/roles.rb +19 -17
  122. data/lib/ddr/vocab/sources/duketerms.rdf +8 -22
  123. data/lib/ddr/vocab/vocabulary.rb +26 -26
  124. data/spec/auth/ability_factory_spec.rb +1 -18
  125. data/spec/auth/ability_spec.rb +15 -119
  126. data/spec/auth/effective_permissions_spec.rb +1 -1
  127. data/spec/auth/effective_roles_spec.rb +1 -1
  128. data/spec/auth/ldap_gateway_spec.rb +9 -0
  129. data/spec/contacts/contacts_spec.rb +26 -0
  130. data/spec/controllers/including_role_based_access_controls_enforcement_spec.rb +5 -5
  131. data/spec/derivatives/multires_image_spec.rb +48 -0
  132. data/spec/derivatives/png_generator_spec.rb +8 -13
  133. data/spec/derivatives/ptif_generator_spec.rb +11 -9
  134. data/spec/derivatives/thumbnail_spec.rb +48 -0
  135. data/spec/dummy/config/environments/test.rb +1 -1
  136. data/spec/dummy/db/schema.rb +23 -25
  137. data/spec/factories/attachment_factories.rb +2 -2
  138. data/spec/factories/collection_factories.rb +2 -3
  139. data/spec/factories/component_factories.rb +2 -2
  140. data/spec/factories/item_factories.rb +2 -2
  141. data/spec/factories/structure_factories.rb +2 -8
  142. data/spec/factories/test_model_factories.rb +12 -4
  143. data/spec/fixtures/fits/document.xml +44 -42
  144. data/spec/fixtures/fits/image.xml +41 -42
  145. data/spec/helpers/models_helper_spec.rb +11 -0
  146. data/spec/index/filter_spec.rb +30 -208
  147. data/spec/index/filters_spec.rb +17 -0
  148. data/spec/index/query_spec.rb +10 -82
  149. data/spec/jobs/fits_file_characterization_spec.rb +52 -0
  150. data/spec/managers/derivatives_manager_spec.rb +105 -107
  151. data/spec/managers/technical_metadata_manager_spec.rb +27 -34
  152. data/spec/models/active_fedora_base_spec.rb +105 -5
  153. data/spec/models/active_fedora_datastream_spec.rb +39 -106
  154. data/spec/models/admin_set_spec.rb +10 -43
  155. data/spec/models/attachment_spec.rb +2 -3
  156. data/spec/models/collection_spec.rb +11 -225
  157. data/spec/models/component_spec.rb +4 -106
  158. data/spec/models/descriptive_metadata_spec.rb +38 -0
  159. data/spec/models/effective_license_spec.rb +64 -0
  160. data/spec/models/events_spec.rb +59 -52
  161. data/spec/models/file_management_spec.rb +13 -113
  162. data/spec/models/finding_aid_spec.rb +8 -31
  163. data/spec/models/has_admin_metadata_spec.rb +122 -131
  164. data/spec/models/has_children_spec.rb +3 -3
  165. data/spec/models/has_struct_metadata_spec.rb +37 -50
  166. data/spec/models/indexing_spec.rb +23 -160
  167. data/spec/models/item_spec.rb +2 -133
  168. data/spec/models/license_spec.rb +24 -0
  169. data/spec/models/solr_document_spec.rb +47 -236
  170. data/spec/models/struct_div_spec.rb +70 -0
  171. data/spec/models/structure_spec.rb +11 -89
  172. data/spec/models/target_spec.rb +2 -4
  173. data/spec/models/year_facet_spec.rb +23 -50
  174. data/spec/spec_helper.rb +13 -17
  175. data/spec/support/ezid_mock_identifier.rb +2 -2
  176. data/spec/support/shared_examples_for_auth_contexts.rb +0 -33
  177. data/spec/support/shared_examples_for_ddr_models.rb +94 -142
  178. data/spec/support/shared_examples_for_describables.rb +36 -31
  179. data/spec/support/shared_examples_for_governables.rb +2 -3
  180. data/spec/support/shared_examples_for_has_content.rb +46 -101
  181. data/spec/support/shared_examples_for_indexing.rb +6 -6
  182. data/spec/support/shared_examples_for_non_collection_models.rb +1 -32
  183. data/spec/support/structural_metadata_helper.rb +59 -230
  184. data/spec/utils_spec.rb +2 -0
  185. metadata +96 -229
  186. data/.ruby-version +0 -1
  187. data/config/initializers/rsolr_monkey_patches.rb +0 -7
  188. data/config/initializers/rubydora_monkey_patch.rb +0 -11
  189. data/config/locales/ddr-models.en.yml +0 -81
  190. data/db/migrate/20161021201011_add_permanent_id_to_events.rb +0 -8
  191. data/lib/ddr/auth/ability_definitions/admin_set_ability_definitions.rb +0 -9
  192. data/lib/ddr/auth/ability_definitions/lock_ability_definitions.rb +0 -13
  193. data/lib/ddr/auth/ability_definitions/publication_ability_definitions.rb +0 -16
  194. data/lib/ddr/datastreams/administrative_metadata_datastream.rb +0 -75
  195. data/lib/ddr/datastreams/caption_datastream.rb +0 -5
  196. data/lib/ddr/datastreams/content_datastream.rb +0 -17
  197. data/lib/ddr/datastreams/delete_external_files.rb +0 -29
  198. data/lib/ddr/datastreams/external_file_datastream.rb +0 -80
  199. data/lib/ddr/datastreams/intermediate_file_datastream.rb +0 -5
  200. data/lib/ddr/datastreams/multires_image_datastream.rb +0 -5
  201. data/lib/ddr/datastreams/streamable_media_datastream.rb +0 -5
  202. data/lib/ddr/derivatives/png_generator.rb +0 -17
  203. data/lib/ddr/derivatives/ptif_generator.rb +0 -55
  204. data/lib/ddr/derivatives/update_derivatives.rb +0 -25
  205. data/lib/ddr/events/deaccession_event.rb +0 -8
  206. data/lib/ddr/index/field_attribute.rb +0 -22
  207. data/lib/ddr/index/query_params.rb +0 -40
  208. data/lib/ddr/index/sort_order.rb +0 -28
  209. data/lib/ddr/models/cache.rb +0 -20
  210. data/lib/ddr/models/captionable.rb +0 -37
  211. data/lib/ddr/models/contact.rb +0 -23
  212. data/lib/ddr/models/file_characterization.rb +0 -37
  213. data/lib/ddr/models/has_intermediate_file.rb +0 -41
  214. data/lib/ddr/models/language.rb +0 -31
  215. data/lib/ddr/models/media_type.rb +0 -22
  216. data/lib/ddr/models/permanent_id.rb +0 -240
  217. data/lib/ddr/models/rights_statement.rb +0 -25
  218. data/lib/ddr/models/streamable.rb +0 -37
  219. data/lib/ddr/models/structures/agent.rb +0 -49
  220. data/lib/ddr/models/structures/component_type_term.rb +0 -29
  221. data/lib/ddr/models/structures/div.rb +0 -64
  222. data/lib/ddr/models/structures/f_locat.rb +0 -54
  223. data/lib/ddr/models/structures/file.rb +0 -52
  224. data/lib/ddr/models/structures/file_grp.rb +0 -35
  225. data/lib/ddr/models/structures/file_sec.rb +0 -22
  226. data/lib/ddr/models/structures/fptr.rb +0 -31
  227. data/lib/ddr/models/structures/mets_hdr.rb +0 -37
  228. data/lib/ddr/models/structures/mptr.rb +0 -49
  229. data/lib/ddr/models/structures/struct_map.rb +0 -40
  230. data/lib/ddr/models/with_content_file.rb +0 -37
  231. data/spec/datastreams/external_file_datastream_spec.rb +0 -48
  232. data/spec/dummy/config/structure_component_type.yml +0 -18
  233. data/spec/fixtures/abcd1234.vtt +0 -38
  234. data/spec/fixtures/arrow1rightred_e0.gif +0 -0
  235. data/spec/fixtures/extractedText1.txt +0 -1
  236. data/spec/fixtures/extractedText2.txt +0 -1
  237. data/spec/fixtures/extractedText3.txt +0 -3
  238. data/spec/fixtures/imageA.jpg +0 -0
  239. data/spec/fixtures/imageB.jpg +0 -0
  240. data/spec/index/csv_query_result_spec.rb +0 -44
  241. data/spec/index/fields_spec.rb +0 -380
  242. data/spec/index/query_builder_spec.rb +0 -140
  243. data/spec/index/query_clause_spec.rb +0 -68
  244. data/spec/models/cache_spec.rb +0 -32
  245. data/spec/models/contact_spec.rb +0 -56
  246. data/spec/models/descriptive_metadata_datastream_spec.rb +0 -139
  247. data/spec/models/file_characterization_spec.rb +0 -39
  248. data/spec/models/language_spec.rb +0 -59
  249. data/spec/models/media_type_spec.rb +0 -46
  250. data/spec/models/permanent_id_spec.rb +0 -432
  251. data/spec/models/rights_statement_spec.rb +0 -55
  252. data/spec/models/structures/agent_spec.rb +0 -30
  253. data/spec/models/structures/component_type_term_spec.rb +0 -14
  254. data/spec/models/structures/div_spec.rb +0 -26
  255. data/spec/models/structures/f_locat_spec.rb +0 -78
  256. data/spec/models/structures/file_grp_spec.rb +0 -23
  257. data/spec/models/structures/file_sec_spec.rb +0 -22
  258. data/spec/models/structures/file_spec.rb +0 -60
  259. data/spec/models/structures/fptr_spec.rb +0 -23
  260. data/spec/models/structures/mets_hdr_spec.rb +0 -26
  261. data/spec/models/structures/mptr_spec.rb +0 -25
  262. data/spec/models/structures/struct_map_spec.rb +0 -24
  263. data/spec/models/with_content_file_spec.rb +0 -37
  264. data/spec/support/shared_examples_for_associations.rb +0 -8
  265. data/spec/support/shared_examples_for_captionable.rb +0 -23
  266. data/spec/support/shared_examples_for_has_intermediate_file.rb +0 -28
  267. data/spec/support/shared_examples_for_publication.rb +0 -43
  268. data/spec/support/shared_examples_for_streamable_media.rb +0 -23
@@ -1,15 +1,6 @@
1
1
  module Ddr
2
2
  module Models
3
3
  class Base < ActiveFedora::Base
4
- extend Deprecation
5
-
6
- self.deprecation_horizon = 'ddr-models v3.0'
7
-
8
- # Lifecycle events
9
- INGEST = "ingest.repo_object"
10
- UPDATE = "update.repo_object"
11
- DELETE = "delete.repo_object"
12
- DEACCESSION = "deaccession.repo_object"
13
4
 
14
5
  include Describable
15
6
  include Governable
@@ -20,41 +11,9 @@ module Ddr
20
11
  include Indexing
21
12
  include Hydra::Validations
22
13
  include HasAdminMetadata
23
- extend Deprecation
24
-
25
- # Prevent accidental use of #delete which lacks callbacks
26
- private :delete
27
-
28
- define_model_callbacks :deaccession
29
-
30
- before_create :set_ingestion_date, unless: :ingestion_date
31
- before_create :set_ingested_by, if: :performed_by, unless: :ingested_by
32
- before_create :grant_default_roles
33
-
34
- around_save :notify_update, unless: :new_record?
35
- around_save :assign_permanent_id!, if: :assign_permanent_id?, on: :create
36
-
37
- after_create :notify_ingest
38
-
39
- around_deaccession :notify_deaccession
40
- around_destroy :notify_delete
41
14
 
42
- def rights_statement
43
- RightsStatement.call(self)
44
- end
45
- alias_method :effective_license, :rights_statement
46
- deprecation_deprecate :effective_license
47
-
48
- def deaccession
49
- run_callbacks :deaccession do
50
- delete
51
- end
52
- end
53
-
54
- def copy_admin_policy_or_permissions_from(other)
55
- Deprecation.warn(self.class, "`copy_admin_policy_or_permissions_from` is deprecated." \
56
- " Use `copy_admin_policy_or_roles_from` instead.")
57
- copy_admin_policy_or_roles_from(other)
15
+ after_destroy do
16
+ notify_event :deletion
58
17
  end
59
18
 
60
19
  def copy_admin_policy_or_roles_from(other)
@@ -62,8 +21,7 @@ module Ddr
62
21
  end
63
22
 
64
23
  def association_query(association)
65
- # XXX Ideally we would include a clause to limit by AF model, but this should suffice
66
- ActiveFedora::SolrService.construct_query_for_rel(reflections[association].options[:property] => internal_uri)
24
+ raise NotImplementedError, "The previous implementation does not work with ActiveFedora 9."
67
25
  end
68
26
 
69
27
  # e.g., "Collection duke:1"
@@ -83,127 +41,49 @@ module Ddr
83
41
  false
84
42
  end
85
43
 
86
- def publishable?
87
- raise NotImplementedError, "Must be implemented by subclasses"
88
- end
89
-
90
- def save(options={})
91
- cache.with(options) { super }
92
- end
93
-
94
- def datastreams_changed
95
- datastreams.select { |dsid, ds| ds.changed? }
96
- end
97
-
98
- def new_datastreams_having_content
99
- datastreams.select { |dsid, ds| ds.new? && ds.has_content? }
100
- end
101
-
102
- def datastreams_having_content
103
- datastreams.select { |dsid, ds| ds.has_content? }
104
- end
105
- alias_method :attached_files_having_content, :datastreams_having_content
106
- alias_method :datastreams_to_validate, :datastreams_having_content
107
- deprecation_deprecate :datastreams_to_validate
108
-
109
- def datastream_history
110
- datastreams_having_content.each_with_object({}) do |(dsid, ds), memo|
111
- memo[dsid] = ds.version_history
112
- end
113
- end
114
-
115
- def parent_id
116
- parent.id
117
- rescue NoMethodError
118
- nil
119
- end
120
-
121
- private
122
-
123
- def grant_default_roles
124
- roles.grant *default_roles
125
- end
126
-
127
- def default_roles
128
- []
129
- end
130
-
131
- def cache
132
- @__cache ||= Cache.new
133
- end
134
-
135
- def performed_by
136
- if user = cache.get(:user)
137
- user.to_s
44
+ # Moves the first (descriptive metadata) identifier into
45
+ # (administrative metadata) local_id according to the following
46
+ # rubric:
47
+ #
48
+ # No existing local_id:
49
+ # - Set local_id to first identifier value
50
+ # - Remove first identifier value
51
+ #
52
+ # Existing local_id:
53
+ # Same as first identifier value
54
+ # - Remove first identifier value
55
+ # Not same as first identifier value
56
+ # :replace option is true
57
+ # - Set local_id to first identifier value
58
+ # - Remove first identifier value
59
+ # :replace option is false
60
+ # - Do nothing
61
+ #
62
+ # Returns true or false depending on whether the object was
63
+ # changed by this method
64
+ def move_first_identifier_to_local_id(replace: true)
65
+ moved = false
66
+ identifiers = descMetadata.identifier.to_a
67
+ first_id = identifiers.shift
68
+ if first_id
69
+ if local_id.blank?
70
+ self.local_id = first_id
71
+ self.descMetadata.identifier = identifiers
72
+ moved = true
73
+ else
74
+ if local_id == first_id
75
+ self.descMetadata.identifier = identifiers
76
+ moved = true
77
+ else
78
+ if replace
79
+ self.local_id = first_id
80
+ self.descMetadata.identifier = identifiers
81
+ moved = true
82
+ end
83
+ end
84
+ end
138
85
  end
139
- end
140
-
141
- def set_ingested_by
142
- self.ingested_by = performed_by
143
- end
144
-
145
- def set_ingestion_date
146
- self.ingestion_date = Time.now.utc.iso8601
147
- end
148
-
149
- def default_notification_payload
150
- cache.slice(:summary, :comment, :detail)
151
- .merge(pid: pid,
152
- user_key: performed_by,
153
- permanent_id: permanent_id,
154
- model: self.class.to_s,
155
- parent: parent_id,
156
- skip_structure_updates: cache.fetch(:skip_structure_updates, false))
157
- end
158
-
159
- def notify_ingest
160
- payload = default_notification_payload.merge(
161
- event_date_time: ingestion_date,
162
- datastreams_changed: attached_files_having_content.keys
163
- )
164
- ActiveSupport::Notifications.instrument(INGEST, payload)
165
- end
166
-
167
- def notify_update
168
- event_params = default_notification_payload.merge(
169
- attributes_changed: changes,
170
- datastreams_changed: datastreams_changed.keys,
171
- new_datastreams: new_datastreams_having_content.keys,
172
- skip_update_derivatives: cache.fetch(:skip_update_derivatives, false)
173
- )
174
- ActiveSupport::Notifications.instrument(UPDATE, event_params) do |payload|
175
- yield
176
- payload[:event_date_time] = modified_date
177
- end
178
- end
179
-
180
- def delete_notification_payload
181
- default_notification_payload.merge(
182
- datastream_history: datastream_history,
183
- create_date: create_date,
184
- modified_date: modified_date
185
- )
186
- end
187
-
188
- def notify_deaccession
189
- ActiveSupport::Notifications.instrument(DEACCESSION, delete_notification_payload) do |payload|
190
- yield
191
- end
192
- end
193
-
194
- def notify_delete
195
- ActiveSupport::Notifications.instrument(DELETE, delete_notification_payload) do |payload|
196
- yield
197
- end
198
- end
199
-
200
- def assign_permanent_id?
201
- permanent_id.nil? && Ddr::Models.auto_assign_permanent_id
202
- end
203
-
204
- def assign_permanent_id!
205
- yield
206
- PermanentId.assign!(self)
86
+ moved
207
87
  end
208
88
 
209
89
  end
@@ -1,17 +1,17 @@
1
- module Ddr
2
- module Models
3
- module Describable
4
- extend ActiveSupport::Concern
1
+ module Ddr::Models
2
+ module Describable
3
+ extend ActiveSupport::Concern
5
4
 
6
5
  included do
7
- has_metadata name: Ddr::Datastreams::DESC_METADATA,
8
- type: Ddr::Datastreams::DescriptiveMetadataDatastream,
9
- versionable: true,
10
- label: "Descriptive Metadata for this object",
11
- control_group: 'M'
12
- has_attributes *Ddr::Vocab::Vocabulary.term_names(RDF::DC11),
13
- datastream: Ddr::Datastreams::DESC_METADATA,
14
- multiple: true
6
+ DescriptiveMetadata.mapping.each do |name, term|
7
+ property name, predicate: term.predicate do |index|
8
+ index.as :stored_searchable
9
+ end
10
+ end
11
+ end
12
+
13
+ def descMetadata
14
+ @descMetadata ||= DescriptiveMetadata.new(self)
15
15
  end
16
16
 
17
17
  def has_desc_metadata?
@@ -19,7 +19,7 @@ module Ddr
19
19
  end
20
20
 
21
21
  def desc_metadata_terms *args
22
- return Ddr::Datastreams::DescriptiveMetadataDatastream.term_names if args.empty?
22
+ return DescriptiveMetadata.unqualified_names.sort if args.empty?
23
23
  arg = args.pop
24
24
  terms = case arg.to_sym
25
25
  when :empty
@@ -31,8 +31,8 @@ module Ddr
31
31
  when :required
32
32
  desc_metadata_terms(:defined_attributes).select {|t| required? t}
33
33
  when :dcterms
34
- Ddr::Vocab::Vocabulary.term_names(RDF::DC11) +
35
- (Ddr::Vocab::Vocabulary.term_names(RDF::DC) - Ddr::Vocab::Vocabulary.term_names(RDF::DC11))
34
+ MetadataMapper.dc11.unqualified_names +
35
+ (MetadataMapper.dcterms.unqualified_names - MetadataMapper.dc11.unqualified_names)
36
36
  when :dcterms_elements11
37
37
  Ddr::Vocab::Vocabulary.term_names(RDF::DC11)
38
38
  when :duke
@@ -48,11 +48,10 @@ module Ddr
48
48
  end
49
49
 
50
50
  def desc_metadata_attributes
51
- defattrs = self.class.defined_attributes
52
- defattrs.keys.select {|k| defattrs[k].dsid == "descMetadata"}.map(&:to_sym)
51
+ MetadataMapper.dc11.unqualified_names
53
52
  end
54
53
 
55
- def desc_metadata_values term
54
+ def desc_metadata_values(term)
56
55
  descMetadata.values term
57
56
  end
58
57
 
@@ -60,13 +59,13 @@ module Ddr
60
59
  descMetadata.class.vocabularies
61
60
  end
62
61
 
63
- def set_desc_metadata_values term, values
62
+ def set_desc_metadata_values(term, values)
64
63
  descMetadata.set_values term, values
65
64
  end
66
65
 
67
66
  # Update all descMetadata terms with values in hash
68
67
  # Note that term not having key in hash will be set to nil!
69
- def set_desc_metadata term_values_hash
68
+ def set_desc_metadata(term_values_hash)
70
69
  desc_metadata_terms.each { |t| set_desc_metadata_values(t, term_values_hash[t]) }
71
70
  end
72
71
 
@@ -76,6 +75,5 @@ module Ddr
76
75
  end
77
76
  end
78
77
 
79
- end
80
78
  end
81
79
  end
@@ -17,46 +17,27 @@ module Ddr
17
17
  # Initializers
18
18
  #
19
19
 
20
- initializer "active_fedora.content_model" do
21
- ActiveFedora::ContentModel.module_eval do
22
- # Returns the first known model for the object is equal to or a
23
- # subclass of the object's class.
24
- # This bubbles up, e.g., to prevent mis-casting via `.find`.
25
- def self.best_model_for(obj)
26
- known_models_for(obj).find { |model| model <= obj.class }
27
- end
28
- end
29
- end
30
-
31
- initializer "active_fedora.finder_methods" do
32
- ActiveFedora::FinderMethods.module_eval do
33
- # Override tries to cast by default
34
- def load_from_fedora(pid, cast)
35
- inner = ActiveFedora::DigitalObject.find(klass, pid)
36
- obj = klass.allocate.init_with_object(inner)
37
- if cast != false
38
- obj = obj.adapt_to_cmodel
39
- end
40
- obj
41
- end
42
- end
43
- end
44
-
45
20
  initializer "ddr_models.derivatives" do
46
21
  Ddr::Derivatives.update_derivatives = ENV['DERIVATIVES'] ?
47
22
  ENV['DERIVATIVES'].split(';').map { |deriv| deriv.strip.to_sym } :
48
23
  [ :thumbnail ]
49
24
  end
50
25
 
51
- initializer "ddr_models.image_server" do
52
- Ddr::Models.image_server_url = ENV["IMAGE_SERVER_URL"]
26
+ initializer "ddr_models.external_files" do
27
+ Ddr::Models.external_file_store = ENV["EXTERNAL_FILE_STORE"]
28
+ Ddr::Models.multires_image_external_file_store = ENV["MULTIRES_IMAGE_EXTERNAL_FILE_STORE"]
29
+ Ddr::Models.external_file_subpath_pattern = ENV["EXTERNAL_FILE_SUBPATH_PATTERN"] || "--"
53
30
  end
54
31
 
55
- # Add custom predicates to ActiveFedora
56
- initializer "ddr_models.predicates" do
57
- ActiveFedora::Predicates.set_predicates(Ddr::Metadata::PREDICATES)
32
+ initializer "ddr_models.image_server" do
33
+ Ddr::Models.image_server_url = ENV["IMAGE_SERVER_URL"]
58
34
  end
59
35
 
36
+ # # Add custom predicates to ActiveFedora
37
+ # initializer "ddr_models.predicates" do
38
+ # ActiveFedora::Predicates.set_predicates(Ddr::Metadata::PREDICATES)
39
+ # end
40
+ #
60
41
  # Set superuser group
61
42
  initializer "ddr_auth.superuser" do
62
43
  Ddr::Auth.superuser_group = ENV["SUPERUSER_GROUP"]
@@ -66,11 +47,6 @@ module Ddr
66
47
  Ddr::Auth.collection_creators_group = ENV["COLLECTION_CREATORS_GROUP"]
67
48
  end
68
49
 
69
- # Set metadata managers group
70
- initializer "ddr_auth.metadata_managers_group" do
71
- Ddr::Auth.metadata_managers_group = ENV["METADATA_MANAGERS_GROUP"]
72
- end
73
-
74
50
  initializer "ezid_client" do
75
51
  unless Rails.env.production?
76
52
  require "ezid/test_helper"
@@ -82,10 +58,6 @@ module Ddr
82
58
  Ddr::Models.fits_home = ENV["FITS_HOME"]
83
59
  end
84
60
 
85
- initializer "vips_path" do
86
- Ddr::Models.vips_path = ENV["VIPS_PATH"]
87
- end
88
-
89
61
  initializer "ddr_antivirus" do
90
62
  require "ddr-antivirus"
91
63
  if Rails.env.test?
@@ -11,8 +11,5 @@ module Ddr
11
11
 
12
12
  # Content model casting error
13
13
  class ContentModelError < Error; end
14
-
15
- # A model instance was not found
16
- class NotFoundError < Error; end
17
14
  end
18
15
  end
@@ -3,96 +3,60 @@ module Ddr::Models
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
+ attr_accessor :file_to_add
7
+
6
8
  define_model_callbacks :add_file
7
9
  before_add_file :virus_scan
8
- after_add_file :set_original_filename
9
- after_save :create_virus_check_event
10
- end
11
10
 
12
- FileToAdd = Struct.new(:dsid, :source_path, :original_filename)
11
+ after_save :notify_virus_scan_results
13
12
 
14
- # @param file [String, File, ActionDispatch::Http::UploadedFile]
15
- # The file, or path to file, to add.
16
- # @param dsid [String] The datastream ID to which file should be added.
17
- # @param mime_type [String] Explicit mime type to set
18
- # (otherwise discerned from file path or name).
19
- # @param external [Boolean] Add file to external datastream.
20
- # Not required for external datastream classes
21
- # or datastream instances having controlGroup 'E'.
22
- def add_file(file, dsid, mime_type: nil, external: false, original_filename: nil)
23
- mime_type ||= MediaType.call(file) # XXX Should we use original_filename, if present?
24
- source_path = Ddr::Utils.file_path(file)
25
- original_filename ||= Ddr::Utils.file_name(file)
26
- file_to_add = FileToAdd.new(dsid, source_path, original_filename)
27
- cache.with(file_to_add: file_to_add) do
28
- run_callbacks(:add_file) do
29
- if external || ( datastreams.include?(dsid) && datastreams[dsid].external? )
30
- add_external_file(file, dsid, mime_type: mime_type)
31
- else
32
- add_file_datastream(file, dsid: dsid, mimeType: mime_type)
33
- end
34
- end
35
- end
36
13
  end
37
14
 
38
- def add_file_datastream(file, opts={})
39
- if Ddr::Utils.file_path?(file)
40
- file = File.new(file, "rb")
41
- end
42
- super
43
- end
15
+ # Adds ActiveFedora::File
16
+ # Overrides ActiveFedora::AttachedFiles#add_file(file, opts)
17
+ #
18
+ # Options:
19
+ #
20
+ # :path - The path of the child resource to create
21
+ #
22
+ # :mime_type - Explicit mime type to set (otherwise discerned from file path or name)
23
+ #
24
+ # :original_name - A String value will be understood as the original name of the file.
25
+ # Default processing will take the file basename as the original name.
26
+ def add_file file, opts={}
27
+ opts[:mime_type] ||= Ddr::Utils.mime_type_for(file)
28
+ opts[:original_name] ||= Ddr::Utils.file_name_for(file)
44
29
 
45
- # @api private
46
- # Normally this method should not be called directly.
47
- # Call `add_file` with dsid for external datastream, or with
48
- # `:external=>true` option if no spec for dsid.
49
- def add_external_file(file, dsid, mime_type: nil)
50
- file_path = Ddr::Utils.file_path(file) # raises ArgumentError
51
- ds = datastreams[dsid] || add_external_datastream(dsid)
52
- unless ds.external?
53
- raise ArgumentError, "Cannot add external file to non-external datastream."
30
+ # @file_to_add is set for callbacks to access the data
31
+ self.file_to_add = file
32
+
33
+ run_callbacks(:add_file) do
34
+ super
54
35
  end
55
- ds.add_file(file_path, mime_type: mime_type)
56
- end
57
36
 
58
- def external_datastreams
59
- datastreams.values.select { |ds| ds.external? }
37
+ # clear the instance data
38
+ self.file_to_add = nil
60
39
  end
61
40
 
62
- def external_datastream_file_paths
63
- external_datastreams.map(&:file_paths).flatten
64
- end
41
+ protected
65
42
 
66
- def add_external_datastream dsid, opts={}
67
- create_datastream(Ddr::Datastreams::ExternalFileDatastream, dsid).tap do |ds|
68
- add_datastream(ds)
69
- self.class.build_datastream_accessor(dsid)
70
- end
71
- end
43
+ FileToAdd = Struct.new(:file, :dsid, :original_name)
72
44
 
73
- protected
45
+ def virus_scan_results
46
+ @virus_scan_results ||= []
47
+ end
74
48
 
75
49
  def virus_scan
76
- file_to_add = cache.get(:file_to_add)
77
- result = Ddr::Actions::VirusCheck.call(file_to_add.source_path)
78
- if file_to_add.dsid == Ddr::Datastreams::CONTENT
79
- cache.put(:virus_scan_result, result)
80
- end
81
- rescue ArgumentError => e # file is a blob (string)
50
+ path = Ddr::Utils.file_path(file_to_add)
51
+ virus_scan_results << Ddr::Actions::VirusCheck.call(path)
52
+ rescue ArgumentError => e # file is a blob
82
53
  logger.error(e)
83
54
  end
84
55
 
85
- def create_virus_check_event
86
- if result = cache.get(:virus_scan_result)
87
- Ddr::Events::VirusCheckEvent.create(result.merge(pid: pid))
88
- end
89
- end
90
-
91
- def set_original_filename
92
- if file_to_add = cache.get(:file_to_add)
93
- if file_to_add.dsid == Ddr::Datastreams::CONTENT
94
- self.original_filename = file_to_add.original_filename
95
- end
56
+ def notify_virus_scan_results
57
+ while result = virus_scan_results.shift
58
+ result.merge! pid: pid
59
+ ActiveSupport::Notifications.instrument(Ddr::Notifications::VIRUS_CHECK, result)
96
60
  end
97
61
  end
98
62