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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.travis.yml +7 -6
- data/Gemfile +2 -3
- data/Rakefile +5 -5
- data/app/controllers/users/sessions_controller.rb +5 -0
- data/app/helpers/models_helper.rb +7 -0
- data/app/models/attachment.rb +3 -5
- data/app/models/collection.rb +12 -79
- data/app/models/component.rb +8 -67
- data/app/models/item.rb +8 -73
- data/app/models/target.rb +6 -5
- data/config/initializers/active_fedora_base.rb +11 -30
- data/config/initializers/{active_fedora_datastream.rb → active_fedora_file.rb} +1 -1
- data/config/initializers/devise.rb +2 -3
- data/config/initializers/subscriptions.rb +2 -19
- data/ddr-models.gemspec +10 -14
- data/lib/ddr/actions/fixity_check.rb +1 -1
- data/lib/ddr/actions/virus_check.rb +17 -10
- data/lib/ddr/auth.rb +6 -38
- data/lib/ddr/auth/ability.rb +1 -5
- data/lib/ddr/auth/ability_definitions/collection_ability_definitions.rb +0 -16
- data/lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb +10 -4
- data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +16 -9
- data/lib/ddr/auth/ability_factory.rb +25 -2
- data/lib/ddr/auth/abstract_ability.rb +1 -2
- data/lib/ddr/auth/auth_context.rb +0 -18
- data/lib/ddr/auth/auth_context_factory.rb +2 -0
- data/lib/ddr/auth/group.rb +0 -6
- data/lib/ddr/auth/grouper_gateway.rb +0 -24
- data/lib/ddr/auth/permissions.rb +1 -12
- data/lib/ddr/auth/role_based_access_controls_enforcement.rb +5 -5
- data/lib/ddr/auth/roles.rb +1 -11
- data/lib/ddr/auth/roles/role_set.rb +0 -7
- data/lib/ddr/auth/roles/roles_datastream.rb +9 -0
- data/lib/ddr/contacts.rb +25 -0
- data/lib/ddr/datastreams.rb +10 -28
- data/lib/ddr/datastreams/datastream_behavior.rb +30 -100
- data/lib/ddr/datastreams/descriptive_metadata_datastream.rb +28 -31
- data/lib/ddr/datastreams/fits_datastream.rb +9 -22
- data/lib/ddr/datastreams/metadata_datastream.rb +17 -31
- data/lib/ddr/derivatives.rb +13 -16
- data/lib/ddr/derivatives/derivative.rb +68 -0
- data/lib/ddr/derivatives/{generator.rb → generators/generator.rb} +11 -7
- data/lib/ddr/derivatives/generators/png_generator.rb +23 -0
- data/lib/ddr/derivatives/generators/ptif_generator.rb +56 -0
- data/lib/ddr/derivatives/multires_image.rb +59 -0
- data/lib/ddr/derivatives/thumbnail.rb +36 -0
- data/lib/ddr/events.rb +0 -1
- data/lib/ddr/events/deletion_event.rb +9 -5
- data/lib/ddr/events/event.rb +8 -13
- data/lib/ddr/events/fixity_check_event.rb +0 -6
- data/lib/ddr/events/ingestion_event.rb +9 -5
- data/lib/ddr/events/update_event.rb +4 -17
- data/lib/ddr/index.rb +4 -4
- data/lib/ddr/index/abstract_query_result.rb +4 -3
- data/lib/ddr/index/connection.rb +9 -28
- data/lib/ddr/index/csv_query_result.rb +32 -47
- data/lib/ddr/index/field.rb +1 -11
- data/lib/ddr/index/fields.rb +16 -99
- data/lib/ddr/index/filter.rb +30 -103
- data/lib/ddr/index/filters.rb +19 -0
- data/lib/ddr/index/query.rb +11 -58
- data/lib/ddr/index/query_builder.rb +36 -147
- data/lib/ddr/index/query_clause.rb +19 -79
- data/lib/ddr/index/query_result.rb +4 -36
- data/lib/ddr/index/query_value.rb +18 -0
- data/lib/ddr/index/response.rb +2 -19
- data/lib/ddr/jobs.rb +12 -0
- data/lib/ddr/jobs/fits_file_characterization.rb +51 -0
- data/lib/ddr/jobs/permanent_id.rb +23 -0
- data/lib/ddr/managers.rb +1 -0
- data/lib/ddr/managers/derivatives_manager.rb +53 -93
- data/lib/ddr/managers/permanent_id_manager.rb +91 -0
- data/lib/ddr/managers/technical_metadata_manager.rb +10 -24
- data/lib/ddr/managers/workflow_manager.rb +10 -29
- data/lib/ddr/models.rb +50 -101
- data/lib/ddr/models/access_controllable.rb +12 -0
- data/lib/ddr/models/admin_set.rb +5 -16
- data/lib/ddr/models/base.rb +45 -165
- data/lib/ddr/models/describable.rb +19 -21
- data/lib/ddr/models/engine.rb +11 -39
- data/lib/ddr/models/error.rb +0 -3
- data/lib/ddr/models/file_management.rb +36 -72
- data/lib/ddr/models/finding_aid.rb +2 -35
- data/lib/ddr/models/fixity_checkable.rb +4 -0
- data/lib/ddr/models/governable.rb +3 -1
- data/lib/ddr/models/has_admin_metadata.rb +82 -56
- data/lib/ddr/models/has_attachments.rb +3 -1
- data/lib/ddr/models/has_children.rb +3 -7
- data/lib/ddr/models/has_content.rb +35 -32
- data/lib/ddr/models/has_multires_image.rb +7 -12
- data/lib/ddr/models/has_struct_metadata.rb +44 -6
- data/lib/ddr/models/has_thumbnail.rb +1 -4
- data/lib/ddr/models/indexing.rb +97 -186
- data/lib/ddr/models/licenses/admin_policy_license.rb +11 -0
- data/lib/ddr/models/licenses/effective_license.rb +9 -0
- data/lib/ddr/models/licenses/inherited_license.rb +9 -0
- data/lib/ddr/models/licenses/license.rb +21 -0
- data/lib/ddr/models/licenses/parent_license.rb +11 -0
- data/lib/ddr/models/metadata/descriptive_metadata.rb +50 -0
- data/lib/ddr/models/metadata/metadata.rb +37 -0
- data/lib/ddr/models/metadata/metadata_mapper.rb +32 -0
- data/lib/ddr/models/metadata/metadata_mappers.rb +18 -0
- data/lib/ddr/models/metadata/metadata_term.rb +24 -0
- data/lib/ddr/models/metadata/metadata_vocabularies.rb +18 -0
- data/lib/ddr/models/metadata/metadata_vocabulary.rb +34 -0
- data/lib/ddr/models/solr_document.rb +24 -156
- data/lib/ddr/models/struct_div.rb +63 -0
- data/lib/ddr/models/structure.rb +39 -175
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/models/year_facet.rb +118 -60
- data/lib/ddr/notifications.rb +12 -10
- data/lib/ddr/utils.rb +15 -28
- data/lib/ddr/vocab.rb +17 -15
- data/lib/ddr/vocab/asset.rb +17 -42
- data/lib/ddr/vocab/contact.rb +7 -5
- data/lib/ddr/vocab/display.rb +8 -6
- data/lib/ddr/vocab/duke_terms.rb +10 -8
- data/lib/ddr/vocab/rdf_vocabulary_parser.rb +39 -37
- data/lib/ddr/vocab/roles.rb +19 -17
- data/lib/ddr/vocab/sources/duketerms.rdf +8 -22
- data/lib/ddr/vocab/vocabulary.rb +26 -26
- data/spec/auth/ability_factory_spec.rb +1 -18
- data/spec/auth/ability_spec.rb +15 -119
- data/spec/auth/effective_permissions_spec.rb +1 -1
- data/spec/auth/effective_roles_spec.rb +1 -1
- data/spec/auth/ldap_gateway_spec.rb +9 -0
- data/spec/contacts/contacts_spec.rb +26 -0
- data/spec/controllers/including_role_based_access_controls_enforcement_spec.rb +5 -5
- data/spec/derivatives/multires_image_spec.rb +48 -0
- data/spec/derivatives/png_generator_spec.rb +8 -13
- data/spec/derivatives/ptif_generator_spec.rb +11 -9
- data/spec/derivatives/thumbnail_spec.rb +48 -0
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/db/schema.rb +23 -25
- data/spec/factories/attachment_factories.rb +2 -2
- data/spec/factories/collection_factories.rb +2 -3
- data/spec/factories/component_factories.rb +2 -2
- data/spec/factories/item_factories.rb +2 -2
- data/spec/factories/structure_factories.rb +2 -8
- data/spec/factories/test_model_factories.rb +12 -4
- data/spec/fixtures/fits/document.xml +44 -42
- data/spec/fixtures/fits/image.xml +41 -42
- data/spec/helpers/models_helper_spec.rb +11 -0
- data/spec/index/filter_spec.rb +30 -208
- data/spec/index/filters_spec.rb +17 -0
- data/spec/index/query_spec.rb +10 -82
- data/spec/jobs/fits_file_characterization_spec.rb +52 -0
- data/spec/managers/derivatives_manager_spec.rb +105 -107
- data/spec/managers/technical_metadata_manager_spec.rb +27 -34
- data/spec/models/active_fedora_base_spec.rb +105 -5
- data/spec/models/active_fedora_datastream_spec.rb +39 -106
- data/spec/models/admin_set_spec.rb +10 -43
- data/spec/models/attachment_spec.rb +2 -3
- data/spec/models/collection_spec.rb +11 -225
- data/spec/models/component_spec.rb +4 -106
- data/spec/models/descriptive_metadata_spec.rb +38 -0
- data/spec/models/effective_license_spec.rb +64 -0
- data/spec/models/events_spec.rb +59 -52
- data/spec/models/file_management_spec.rb +13 -113
- data/spec/models/finding_aid_spec.rb +8 -31
- data/spec/models/has_admin_metadata_spec.rb +122 -131
- data/spec/models/has_children_spec.rb +3 -3
- data/spec/models/has_struct_metadata_spec.rb +37 -50
- data/spec/models/indexing_spec.rb +23 -160
- data/spec/models/item_spec.rb +2 -133
- data/spec/models/license_spec.rb +24 -0
- data/spec/models/solr_document_spec.rb +47 -236
- data/spec/models/struct_div_spec.rb +70 -0
- data/spec/models/structure_spec.rb +11 -89
- data/spec/models/target_spec.rb +2 -4
- data/spec/models/year_facet_spec.rb +23 -50
- data/spec/spec_helper.rb +13 -17
- data/spec/support/ezid_mock_identifier.rb +2 -2
- data/spec/support/shared_examples_for_auth_contexts.rb +0 -33
- data/spec/support/shared_examples_for_ddr_models.rb +94 -142
- data/spec/support/shared_examples_for_describables.rb +36 -31
- data/spec/support/shared_examples_for_governables.rb +2 -3
- data/spec/support/shared_examples_for_has_content.rb +46 -101
- data/spec/support/shared_examples_for_indexing.rb +6 -6
- data/spec/support/shared_examples_for_non_collection_models.rb +1 -32
- data/spec/support/structural_metadata_helper.rb +59 -230
- data/spec/utils_spec.rb +2 -0
- metadata +96 -229
- data/.ruby-version +0 -1
- data/config/initializers/rsolr_monkey_patches.rb +0 -7
- data/config/initializers/rubydora_monkey_patch.rb +0 -11
- data/config/locales/ddr-models.en.yml +0 -81
- data/db/migrate/20161021201011_add_permanent_id_to_events.rb +0 -8
- data/lib/ddr/auth/ability_definitions/admin_set_ability_definitions.rb +0 -9
- data/lib/ddr/auth/ability_definitions/lock_ability_definitions.rb +0 -13
- data/lib/ddr/auth/ability_definitions/publication_ability_definitions.rb +0 -16
- data/lib/ddr/datastreams/administrative_metadata_datastream.rb +0 -75
- data/lib/ddr/datastreams/caption_datastream.rb +0 -5
- data/lib/ddr/datastreams/content_datastream.rb +0 -17
- data/lib/ddr/datastreams/delete_external_files.rb +0 -29
- data/lib/ddr/datastreams/external_file_datastream.rb +0 -80
- data/lib/ddr/datastreams/intermediate_file_datastream.rb +0 -5
- data/lib/ddr/datastreams/multires_image_datastream.rb +0 -5
- data/lib/ddr/datastreams/streamable_media_datastream.rb +0 -5
- data/lib/ddr/derivatives/png_generator.rb +0 -17
- data/lib/ddr/derivatives/ptif_generator.rb +0 -55
- data/lib/ddr/derivatives/update_derivatives.rb +0 -25
- data/lib/ddr/events/deaccession_event.rb +0 -8
- data/lib/ddr/index/field_attribute.rb +0 -22
- data/lib/ddr/index/query_params.rb +0 -40
- data/lib/ddr/index/sort_order.rb +0 -28
- data/lib/ddr/models/cache.rb +0 -20
- data/lib/ddr/models/captionable.rb +0 -37
- data/lib/ddr/models/contact.rb +0 -23
- data/lib/ddr/models/file_characterization.rb +0 -37
- data/lib/ddr/models/has_intermediate_file.rb +0 -41
- data/lib/ddr/models/language.rb +0 -31
- data/lib/ddr/models/media_type.rb +0 -22
- data/lib/ddr/models/permanent_id.rb +0 -240
- data/lib/ddr/models/rights_statement.rb +0 -25
- data/lib/ddr/models/streamable.rb +0 -37
- data/lib/ddr/models/structures/agent.rb +0 -49
- data/lib/ddr/models/structures/component_type_term.rb +0 -29
- data/lib/ddr/models/structures/div.rb +0 -64
- data/lib/ddr/models/structures/f_locat.rb +0 -54
- data/lib/ddr/models/structures/file.rb +0 -52
- data/lib/ddr/models/structures/file_grp.rb +0 -35
- data/lib/ddr/models/structures/file_sec.rb +0 -22
- data/lib/ddr/models/structures/fptr.rb +0 -31
- data/lib/ddr/models/structures/mets_hdr.rb +0 -37
- data/lib/ddr/models/structures/mptr.rb +0 -49
- data/lib/ddr/models/structures/struct_map.rb +0 -40
- data/lib/ddr/models/with_content_file.rb +0 -37
- data/spec/datastreams/external_file_datastream_spec.rb +0 -48
- data/spec/dummy/config/structure_component_type.yml +0 -18
- data/spec/fixtures/abcd1234.vtt +0 -38
- data/spec/fixtures/arrow1rightred_e0.gif +0 -0
- data/spec/fixtures/extractedText1.txt +0 -1
- data/spec/fixtures/extractedText2.txt +0 -1
- data/spec/fixtures/extractedText3.txt +0 -3
- data/spec/fixtures/imageA.jpg +0 -0
- data/spec/fixtures/imageB.jpg +0 -0
- data/spec/index/csv_query_result_spec.rb +0 -44
- data/spec/index/fields_spec.rb +0 -380
- data/spec/index/query_builder_spec.rb +0 -140
- data/spec/index/query_clause_spec.rb +0 -68
- data/spec/models/cache_spec.rb +0 -32
- data/spec/models/contact_spec.rb +0 -56
- data/spec/models/descriptive_metadata_datastream_spec.rb +0 -139
- data/spec/models/file_characterization_spec.rb +0 -39
- data/spec/models/language_spec.rb +0 -59
- data/spec/models/media_type_spec.rb +0 -46
- data/spec/models/permanent_id_spec.rb +0 -432
- data/spec/models/rights_statement_spec.rb +0 -55
- data/spec/models/structures/agent_spec.rb +0 -30
- data/spec/models/structures/component_type_term_spec.rb +0 -14
- data/spec/models/structures/div_spec.rb +0 -26
- data/spec/models/structures/f_locat_spec.rb +0 -78
- data/spec/models/structures/file_grp_spec.rb +0 -23
- data/spec/models/structures/file_sec_spec.rb +0 -22
- data/spec/models/structures/file_spec.rb +0 -60
- data/spec/models/structures/fptr_spec.rb +0 -23
- data/spec/models/structures/mets_hdr_spec.rb +0 -26
- data/spec/models/structures/mptr_spec.rb +0 -25
- data/spec/models/structures/struct_map_spec.rb +0 -24
- data/spec/models/with_content_file_spec.rb +0 -37
- data/spec/support/shared_examples_for_associations.rb +0 -8
- data/spec/support/shared_examples_for_captionable.rb +0 -23
- data/spec/support/shared_examples_for_has_intermediate_file.rb +0 -28
- data/spec/support/shared_examples_for_publication.rb +0 -43
- data/spec/support/shared_examples_for_streamable_media.rb +0 -23
data/lib/ddr/models/base.rb
CHANGED
@@ -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
|
-
|
43
|
-
|
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
|
-
|
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
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
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
|
3
|
-
|
4
|
-
extend ActiveSupport::Concern
|
1
|
+
module Ddr::Models
|
2
|
+
module Describable
|
3
|
+
extend ActiveSupport::Concern
|
5
4
|
|
6
5
|
included do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
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
|
-
|
35
|
-
|
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
|
-
|
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
|
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
|
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
|
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
|
data/lib/ddr/models/engine.rb
CHANGED
@@ -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.
|
52
|
-
Ddr::Models.
|
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
|
-
|
56
|
-
|
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?
|
data/lib/ddr/models/error.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
59
|
-
|
37
|
+
# clear the instance data
|
38
|
+
self.file_to_add = nil
|
60
39
|
end
|
61
40
|
|
62
|
-
|
63
|
-
external_datastreams.map(&:file_paths).flatten
|
64
|
-
end
|
41
|
+
protected
|
65
42
|
|
66
|
-
|
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
|
-
|
45
|
+
def virus_scan_results
|
46
|
+
@virus_scan_results ||= []
|
47
|
+
end
|
74
48
|
|
75
49
|
def virus_scan
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
|