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,25 +0,0 @@
1
- module Ddr::Derivatives
2
- class UpdateDerivatives
3
-
4
- def self.call(*args)
5
- event = ActiveSupport::Notifications::Event.new(*args)
6
- payload = event.payload
7
- return false if payload[:skip_update_derivatives]
8
- if event.name == "delete.repo_file" &&
9
- !file_ids.include?(payload[:file_id])
10
- return false
11
- end
12
- if event.name =~ /\.repo_object\z/ &&
13
- (file_ids & payload[:datastreams_changed]).empty?
14
- return false
15
- end
16
- obj = ActiveFedora::Base.find(payload[:pid])
17
- obj.derivatives.update_derivatives(:later)
18
- end
19
-
20
- def self.file_ids
21
- Ddr::Datastreams.update_derivatives_on_changed
22
- end
23
-
24
- end
25
- end
@@ -1,8 +0,0 @@
1
- module Ddr::Events
2
- class DeaccessionEvent < Event
3
- include PreservationEventBehavior
4
-
5
- self.description = "Object deaccessioned"
6
- self.preservation_event_type = :dea
7
- end
8
- end
@@ -1,22 +0,0 @@
1
- require "virtus"
2
-
3
- module Ddr::Index
4
- class FieldAttribute < Virtus::Attribute
5
-
6
- def self.coerce(value)
7
- case value
8
- when Field
9
- value
10
- when String
11
- Field.new(value)
12
- when Symbol
13
- Fields.get(value)
14
- end
15
- end
16
-
17
- def coerce(value)
18
- self.class.coerce(value)
19
- end
20
-
21
- end
22
- end
@@ -1,40 +0,0 @@
1
- module Ddr::Index
2
- class QueryParams
3
-
4
- attr_reader :query
5
-
6
- def initialize(query)
7
- @query = query
8
- end
9
-
10
- def params
11
- { q: q_param,
12
- fq: filter_queries,
13
- fl: fields,
14
- sort: sort,
15
- rows: rows,
16
- }.select { |k, v| v.present? }
17
- end
18
-
19
- def q_param
20
- query.q.to_s
21
- end
22
-
23
- def filter_queries
24
- query.filter_clauses.map(&:to_s)
25
- end
26
-
27
- def fields
28
- query.fields.join(",")
29
- end
30
-
31
- def sort
32
- query.sort.join(",")
33
- end
34
-
35
- def rows
36
- query.rows
37
- end
38
-
39
- end
40
- end
@@ -1,28 +0,0 @@
1
- require "virtus"
2
-
3
- module Ddr::Index
4
- class SortOrder
5
- include Virtus.value_object
6
-
7
- ASC = "asc"
8
- DESC = "desc"
9
-
10
- values do
11
- attribute :field, FieldAttribute
12
- attribute :order, String
13
- end
14
-
15
- def to_s
16
- [ field, order ].join(" ")
17
- end
18
-
19
- def self.asc(field)
20
- new(field: field, order: ASC)
21
- end
22
-
23
- def self.desc(field)
24
- new(field: field, order: DESC)
25
- end
26
-
27
- end
28
- end
@@ -1,20 +0,0 @@
1
- module Ddr::Models
2
- class Cache < Hash
3
-
4
- def get(key)
5
- self[key]
6
- end
7
-
8
- def put(key, value)
9
- self[key] = value
10
- end
11
-
12
- def with(options, &block)
13
- merge!(options)
14
- block_result = yield
15
- reject! { |k, v| options.include?(k) }
16
- block_result
17
- end
18
-
19
- end
20
- end
@@ -1,37 +0,0 @@
1
- module Ddr::Models
2
- module Captionable
3
- extend ActiveSupport::Concern
4
-
5
- included do
6
- has_file_datastream name: Ddr::Datastreams::CAPTION,
7
- type: Ddr::Datastreams::CaptionDatastream,
8
- versionable: true,
9
- label: "Caption file for this object",
10
- control_group: "E"
11
- end
12
-
13
- def caption_type
14
- datastreams[Ddr::Datastreams::CAPTION].mimeType
15
- end
16
-
17
- def caption_extension
18
- extensions = Ddr::Models.preferred_file_extensions
19
- if extensions.include? caption_type
20
- extensions[caption_type]
21
- else
22
- caption_extension_default
23
- end
24
- end
25
-
26
- def caption_path
27
- datastreams[Ddr::Datastreams::CAPTION].file_path
28
- end
29
-
30
- private
31
-
32
- def caption_extension_default
33
- datastreams[Ddr::Datastreams::CAPTION].default_file_extension
34
- end
35
-
36
- end
37
- end
@@ -1,23 +0,0 @@
1
- require "active_resource"
2
-
3
- module Ddr::Models
4
- class Contact < ActiveResource::Base
5
-
6
- self.site = ENV["DDR_AUX_API_URL"]
7
-
8
- def self.call(slug)
9
- new get(:find, slug: slug)
10
- rescue ActiveResource::ResourceNotFound => e
11
- raise Ddr::Models::NotFoundError, e
12
- end
13
-
14
- def self.keys
15
- all.map(&:slug)
16
- end
17
-
18
- def to_s
19
- name
20
- end
21
-
22
- end
23
- end
@@ -1,37 +0,0 @@
1
- require "delegate"
2
- require "shellwords"
3
-
4
- module Ddr::Models
5
- class FileCharacterization < SimpleDelegator
6
-
7
- class FITSError < Error; end
8
-
9
- def self.call(obj)
10
- new(obj).call
11
- end
12
-
13
- def call
14
- with_content_file do |path|
15
- fits_output = run_fits(path)
16
- reload
17
- fits.content = fits_output
18
- save!
19
- end
20
- end
21
-
22
- private
23
-
24
- def run_fits(path)
25
- output = `#{fits_command} -i #{Shellwords.escape(path)}`
26
- unless $?.success?
27
- raise FITSError, output
28
- end
29
- output
30
- end
31
-
32
- def fits_command
33
- File.join(Ddr::Models.fits_home, 'fits.sh')
34
- end
35
-
36
- end
37
- end
@@ -1,41 +0,0 @@
1
- module Ddr
2
- module Models
3
- module HasIntermediateFile
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- has_file_datastream name: Ddr::Datastreams::INTERMEDIATE_FILE,
8
- type: Ddr::Datastreams::IntermediateFileDatastream,
9
- versionable: true,
10
- label: "Intermediate file for this object",
11
- control_group: "E"
12
-
13
- include FileManagement
14
- end
15
-
16
- def intermediate_type
17
- datastreams[Ddr::Datastreams::INTERMEDIATE_FILE].mimeType
18
- end
19
-
20
- def intermediate_extension
21
- extensions = Ddr::Models.preferred_file_extensions
22
- if extensions.include? intermediate_type
23
- extensions[intermediate_type]
24
- else
25
- intermediate_extension_default
26
- end
27
- end
28
-
29
- def intermediate_path
30
- datastreams[Ddr::Datastreams::INTERMEDIATE_FILE].file_path
31
- end
32
-
33
- private
34
-
35
- def intermediate_extension_default
36
- datastreams[Ddr::Datastreams::INTERMEDIATE_FILE].default_file_extension
37
- end
38
-
39
- end
40
- end
41
- end
@@ -1,31 +0,0 @@
1
- require "active_resource"
2
-
3
- module Ddr::Models
4
- class Language < ActiveResource::Base
5
-
6
- self.site = ENV["DDR_AUX_API_URL"]
7
-
8
- def self.call(obj)
9
- obj.language.map do |lang|
10
- find_by_code(lang)
11
- end
12
- rescue ActiveResource::ResourceNotFound => e
13
- raise Ddr::Models::NotFoundError, e
14
- end
15
-
16
- def self.find_by_code(code)
17
- return unless code
18
- new get(:find, code: code)
19
- end
20
-
21
- def self.codes
22
- all.map(&:code)
23
- end
24
-
25
- def to_s
26
- label
27
- end
28
-
29
- end
30
- end
31
-
@@ -1,22 +0,0 @@
1
- module Ddr::Models
2
- class MediaType
3
-
4
- def self.call(file_or_path)
5
- path = file_or_path.respond_to?(:path) ? file_or_path.path : file_or_path
6
- # Use preferred media type, if available
7
- media_type = Ddr::Models.preferred_media_types[(File.extname(path)).downcase]
8
- if !media_type
9
- if file_or_path.respond_to?(:content_type)
10
- # Rails ActionDispatch::Http::UploadedFile
11
- media_type = file_or_path.content_type
12
- else
13
- # Fall back to first MIME type or default
14
- mime_types = MIME::Types.of(path)
15
- media_type = mime_types.empty? ? Ddr::Models.default_mime_type : mime_types.first.content_type
16
- end
17
- end
18
- media_type
19
- end
20
-
21
- end
22
- end
@@ -1,240 +0,0 @@
1
- require 'ezid-client'
2
-
3
- module Ddr::Models
4
- class PermanentId
5
-
6
- class Error < Ddr::Models::Error; end
7
- class AssignmentFailed < Error; end
8
- class RepoObjectNotPersisted < Error; end
9
- class AlreadyAssigned < AssignmentFailed; end
10
- class IdentifierNotAssigned < Error; end
11
- class IdentifierNotFound < Error; end
12
-
13
- PERMANENT_URL_BASE = "https://idn.duke.edu/".freeze
14
- DEFAULT_STATUS = Ezid::Status::RESERVED
15
- DEFAULT_EXPORT = "no".freeze
16
- DEFAULT_PROFILE = "dc".freeze
17
- DEFAULT_TARGET = "https://repository.duke.edu/id/%s"
18
- FCREPO3_PID = "fcrepo3.pid".freeze
19
- DELETED = "deleted".freeze
20
- DEACCESSIONED = "deaccessioned".freeze
21
-
22
- class_attribute :identifier_class, :identifier_repo_id_field
23
-
24
- self.identifier_class = Ezid::Identifier
25
- self.identifier_class.defaults = {
26
- profile: DEFAULT_PROFILE,
27
- export: DEFAULT_EXPORT,
28
- status: DEFAULT_STATUS,
29
- }
30
-
31
- self.identifier_repo_id_field = FCREPO3_PID
32
-
33
- # ActiveSupport::Notifications event handler
34
- def self.call(*args)
35
- event = ActiveSupport::Notifications::Event.new(*args)
36
- repo_id, identifier_id, reason = event.payload.values_at(:pid, :permanent_id, :reason)
37
- case event.name
38
- when Base::UPDATE
39
- if auto_update? && event.payload[:attributes_changed].include?("workflow_state")
40
- update!(repo_id)
41
- end
42
- when Base::DEACCESSION
43
- if auto_update? && identifier_id
44
- deaccession!(repo_id, identifier_id, reason)
45
- end
46
- when Base::DELETE
47
- if auto_update? && identifier_id
48
- delete!(repo_id, identifier_id, reason)
49
- end
50
- end
51
- end
52
-
53
- def self.auto_update?
54
- Ddr::Models.auto_update_permanent_id
55
- end
56
-
57
- def self.deaccession!(repo_object_or_id, identifier_or_id, reason = nil)
58
- new(repo_object_or_id, identifier_or_id).deaccession!(reason)
59
- end
60
-
61
- def self.delete!(repo_object_or_id, identifier_or_id, reason = nil)
62
- new(repo_object_or_id, identifier_or_id).delete!(reason)
63
- end
64
-
65
- def self.update!(repo_object_or_id)
66
- perm_id = new(repo_object_or_id)
67
- perm_id.update! if perm_id.assigned?
68
- end
69
-
70
- def self.assign!(repo_object_or_id, identifier_or_id = nil)
71
- new(repo_object_or_id, identifier_or_id).assign!
72
- end
73
-
74
- def self.assigned(repo_object_or_id)
75
- perm_id = new(repo_object_or_id)
76
- perm_id.assigned? ? perm_id : nil
77
- end
78
-
79
- def initialize(repo_object_or_id, identifier_or_id = nil)
80
- case repo_object_or_id
81
- when ActiveFedora::Base
82
- raise RepoObjectNotPersisted, "Repository object must be persisted." if repo_object_or_id.new_record?
83
- @repo_object = repo_object_or_id
84
- when String, nil
85
- @repo_id = repo_object_or_id
86
- else
87
- raise TypeError, "#{repo_object_or_id.class} is not expected as the first argument."
88
- end
89
-
90
- case identifier_or_id
91
- when identifier_class
92
- @identifier = identifier_or_id
93
- when String, nil
94
- @identifier_id = identifier_or_id
95
- else
96
- raise TypeError, "#{identifier_or_id.class} is not expected as the second argument."
97
- end
98
- end
99
-
100
- def repo_object
101
- @repo_object ||= ActiveFedora::Base.find(repo_id)
102
- end
103
-
104
- def repo_id
105
- @repo_id ||= @repo_object && @repo_object.id
106
- end
107
-
108
- def assign!(id = nil)
109
- if assigned?
110
- raise AlreadyAssigned,
111
- "Repository object \"#{repo_object.id}\" has already been assigned permanent id \"#{repo_object.permanent_id}\"."
112
- end
113
- @identifier = case id
114
- when identifier_class
115
- id
116
- when String
117
- find_identifier(id)
118
- when nil
119
- mint_identifier
120
- end
121
- repo_object.reload
122
- repo_object.permanent_id = identifier.id
123
- repo_object.permanent_url = PERMANENT_URL_BASE + identifier.id
124
- repo_object.save!
125
- set_metadata!
126
- end
127
-
128
- def assigned?
129
- repo_object.permanent_id
130
- end
131
-
132
- def update!
133
- if !assigned?
134
- raise IdentifierNotAssigned,
135
- "Cannot update identifier for repository object \"#{repo_object.id}\"; not assigned."
136
- end
137
- set_status!
138
- end
139
-
140
- def deaccession!(reason = nil)
141
- delete_or_make_unavailable(reason || DEACCESSIONED)
142
- end
143
-
144
- def delete!(reason = nil)
145
- delete_or_make_unavailable(reason || DELETED)
146
- end
147
-
148
- def identifier
149
- if @identifier.nil?
150
- if identifier_id
151
- @identifier = find_identifier(identifier_id)
152
- elsif assigned?
153
- @identifier = find_identifier(repo_object.permanent_id)
154
- end
155
- end
156
- @identifier
157
- end
158
-
159
- def identifier_id
160
- @identifier_id ||= @identifier && @identifier.id
161
- end
162
-
163
- def set_permanent_url
164
- repo_object.permanent_url = PERMANENT_URL_BASE + identifier.id
165
- end
166
-
167
- def set_metadata!
168
- set_metadata
169
- save
170
- self
171
- end
172
-
173
- def set_metadata
174
- set_target
175
- set_status
176
- set_identifier_repo_id
177
- end
178
-
179
- def set_target
180
- self.target = DEFAULT_TARGET % id
181
- end
182
-
183
- def set_identifier_repo_id
184
- self.identifier_repo_id = repo_object.id
185
- end
186
-
187
- def identifier_repo_id=(val)
188
- if identifier_repo_id
189
- raise Error, "Identifier repository id already set to \"#{identifier_repo_id}\"; cannot change."
190
- end
191
- self[identifier_repo_id_field] = val
192
- end
193
-
194
- def identifier_repo_id
195
- self[identifier_repo_id_field]
196
- end
197
-
198
- def set_status!
199
- save if set_status
200
- end
201
-
202
- def set_status
203
- if repo_object.published? && !public?
204
- public!
205
- elsif repo_object.unpublished? && public?
206
- unavailable!("not published")
207
- end
208
- end
209
-
210
- protected
211
-
212
- def method_missing(name, *args, &block)
213
- identifier.send(name, *args, &block)
214
- end
215
-
216
- private
217
-
218
- def find_identifier(ark)
219
- identifier_class.find(ark)
220
- rescue Ezid::IdentifierNotFoundError => e
221
- raise IdentifierNotFound, e.message
222
- end
223
-
224
- def mint_identifier(*args)
225
- identifier_class.mint(*args)
226
- end
227
-
228
- def delete_or_make_unavailable(reason)
229
- if repo_id && identifier_repo_id && ( identifier_repo_id != repo_id )
230
- raise Error, "Identifier \"#{identifier_id}\" is assigned to a different repository object \"#{repo_id}\"."
231
- end
232
- if reserved?
233
- delete
234
- else
235
- unavailable!(reason) && save
236
- end
237
- end
238
-
239
- end
240
- end