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/version.rb
CHANGED
@@ -1,95 +1,153 @@
|
|
1
1
|
require "date"
|
2
|
-
require "edtf"
|
3
2
|
|
4
3
|
module Ddr::Models
|
5
4
|
class YearFacet
|
6
5
|
|
7
6
|
EARLIEST_YEAR = 1000
|
8
|
-
LATEST_YEAR = Date.today.year + 100
|
9
|
-
VALID_YEARS = (EARLIEST_YEAR..LATEST_YEAR)
|
10
|
-
VALUE_SEP = /;/
|
11
7
|
|
12
8
|
# Between 1965 and 1968
|
13
9
|
BETWEEN = Regexp.new '\A([Bb]etween\s+)(\d{4})(\s+and\s+)(\d{4})\??\z'
|
14
10
|
|
15
|
-
#
|
16
|
-
|
11
|
+
# YYYx (192x)
|
12
|
+
# YYYX (192X)
|
13
|
+
# YYY? (192?)
|
14
|
+
# YYY- (192-)
|
15
|
+
# YYY-? (192-?)
|
16
|
+
IN_DECADE = Regexp.new '\A(\d{3})([xX\-]\??|\?)\z'
|
17
|
+
|
18
|
+
# YYxx (19xx)
|
19
|
+
IN_CENTURY = Regexp.new '\A(\d{2})xx\z'
|
17
20
|
|
18
|
-
#
|
19
|
-
|
21
|
+
# YYY0s (1920s)
|
22
|
+
# YYY0s? (1920s?)
|
23
|
+
DECADE = Regexp.new '\A(\d{3}0)s\??\z'
|
20
24
|
|
21
|
-
#
|
22
|
-
|
25
|
+
# YYYY-MM (2010-01)
|
26
|
+
# YYYY/MM (2010/01)
|
27
|
+
YEAR_MONTH = Regexp.new '\A(\d{4})[/-](0[1-9]|1[0-2])\z'
|
23
28
|
|
24
|
-
#
|
25
|
-
|
29
|
+
# YYYY-YYYY (1935-2010)
|
30
|
+
# YYYY/YYYY (1935/2010)
|
31
|
+
YEAR_RANGE = Regexp.new '\A(\d{4})[/-](\d{4})\z'
|
26
32
|
|
27
|
-
#
|
28
|
-
|
33
|
+
# YYYY (1979)
|
34
|
+
YEAR = Regexp.new '\A\d{4}\z'
|
29
35
|
|
30
|
-
|
31
|
-
END_DECADE = Regexp.new '(?<=\/\d{3})[uxX]'
|
36
|
+
SQUARE_BRACKETS = Regexp.new '[\[\]]'
|
32
37
|
|
33
|
-
#
|
34
|
-
|
38
|
+
# c. 1920
|
39
|
+
# ca. 1920
|
40
|
+
# c1920
|
41
|
+
CIRCA = Regexp.new '\b(circa\s+|ca?\.\s*|c(?=\d{4}[^\d]*))'
|
35
42
|
|
36
|
-
|
37
|
-
|
43
|
+
class << self
|
44
|
+
def call(obj)
|
45
|
+
new(obj).values
|
46
|
+
end
|
38
47
|
end
|
39
48
|
|
40
|
-
attr_reader :
|
49
|
+
attr_reader :obj, :values
|
41
50
|
|
42
|
-
def initialize(
|
43
|
-
@
|
51
|
+
def initialize(obj)
|
52
|
+
@obj = obj
|
53
|
+
@values = []
|
54
|
+
facet_values
|
44
55
|
end
|
45
56
|
|
46
|
-
def
|
47
|
-
|
48
|
-
date.split(
|
49
|
-
value
|
50
|
-
|
51
|
-
years
|
52
|
-
|
53
|
-
facet_values.push(*years)
|
57
|
+
def facet_values
|
58
|
+
obj.descMetadata.date.each do |date|
|
59
|
+
date.split(/;/).each do |value|
|
60
|
+
clean! value
|
61
|
+
years = extract_years(value)
|
62
|
+
validate! years
|
63
|
+
values.push *years
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
57
67
|
|
58
|
-
|
68
|
+
def extract_years(value)
|
69
|
+
years = match_years(value) || parse_year(value)
|
70
|
+
Array(years)
|
71
|
+
end
|
72
|
+
|
73
|
+
def clean!(value)
|
74
|
+
value.strip!
|
75
|
+
value.gsub! SQUARE_BRACKETS, ""
|
76
|
+
value.gsub! CIRCA, ""
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate!(years)
|
80
|
+
years = years & valid_years.to_a
|
81
|
+
end
|
82
|
+
|
83
|
+
def parse_year(value)
|
84
|
+
Date.parse(value).year
|
85
|
+
rescue ArgumentError
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def valid_years
|
90
|
+
(EARLIEST_YEAR..latest_year)
|
91
|
+
end
|
92
|
+
|
93
|
+
def latest_year
|
94
|
+
Date.today.year + 100
|
95
|
+
end
|
96
|
+
|
97
|
+
def match_years(value)
|
98
|
+
result = match_year_range(value) ||
|
99
|
+
match_year_month(value) ||
|
100
|
+
match_year(value) ||
|
101
|
+
match_in_decade(value) ||
|
102
|
+
match_in_century(value) ||
|
103
|
+
match_decade(value) ||
|
104
|
+
match_between(value)
|
105
|
+
first_year, last_year = Array(result).map(&:to_i)
|
106
|
+
last_year ? (first_year..last_year) : first_year
|
107
|
+
end
|
108
|
+
|
109
|
+
def match_year_range(value)
|
110
|
+
if m = YEAR_RANGE.match(value)
|
111
|
+
m[1, 2]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def match_year_month(value)
|
116
|
+
if m = YEAR_MONTH.match(value)
|
117
|
+
m[1]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def match_year(value)
|
122
|
+
if m = YEAR.match(value)
|
123
|
+
value
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def match_in_decade(value)
|
128
|
+
if m = IN_DECADE.match(value)
|
129
|
+
[ "#{m[1]}0", "#{m[1]}9" ]
|
130
|
+
end
|
131
|
+
end
|
59
132
|
|
60
|
-
def
|
61
|
-
|
133
|
+
def match_in_century(value)
|
134
|
+
if m = IN_CENTURY.match(value)
|
135
|
+
[ "#{m[1]}00", "#{m[1]}99" ]
|
136
|
+
end
|
62
137
|
end
|
63
138
|
|
64
|
-
def
|
139
|
+
def match_decade(value)
|
140
|
+
if m = DECADE.match(value)
|
141
|
+
[ m[1], m[1].sub(/0\z/, "9") ]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def match_between(value)
|
65
146
|
if m = BETWEEN.match(value)
|
66
147
|
value.sub! m[1], "" # [Bb]etween
|
67
|
-
value.sub! m[3], "
|
148
|
+
value.sub! m[3], "-" # and
|
149
|
+
match_year_range(value)
|
68
150
|
end
|
69
|
-
substitutions.reduce(value) { |memo, (regexp, repl)| memo.gsub(regexp, repl) }
|
70
|
-
end
|
71
|
-
|
72
|
-
def substitutions
|
73
|
-
[
|
74
|
-
[ CIRCA, "" ],
|
75
|
-
[ YEAR_RANGE, "/" ],
|
76
|
-
[ DECADE, "x" ],
|
77
|
-
[ MONTH, "-" ],
|
78
|
-
[ START_DECADE, "0" ],
|
79
|
-
[ END_DECADE, "9" ],
|
80
|
-
[ CENTURY, "xx" ],
|
81
|
-
]
|
82
|
-
end
|
83
|
-
|
84
|
-
def edtf_years(value)
|
85
|
-
case parsed = EDTF.parse!(value)
|
86
|
-
when Date, EDTF::Season
|
87
|
-
parsed.year
|
88
|
-
when EDTF::Set, EDTF::Interval, EDTF::Epoch
|
89
|
-
parsed.map(&:year).uniq
|
90
|
-
end
|
91
|
-
rescue ArgumentError # EDTF cannot parse
|
92
|
-
nil
|
93
151
|
end
|
94
152
|
|
95
153
|
end
|
data/lib/ddr/notifications.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
module Ddr
|
1
|
+
module Ddr
|
2
|
+
module Notifications
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
FIXITY_CHECK = "fixity_check.events.ddr"
|
5
|
+
VIRUS_CHECK = "virus_check.events.ddr"
|
6
|
+
CREATION = "creation.events.ddr"
|
7
|
+
UPDATE = "update.events.ddr"
|
8
|
+
DELETION = "deletion.events.ddr"
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def self.notify_event(type, args={})
|
11
|
+
name = "#{type}.events.ddr"
|
12
|
+
ActiveSupport::Notifications.instrument(name, args)
|
13
|
+
end
|
13
14
|
|
15
|
+
end
|
14
16
|
end
|
data/lib/ddr/utils.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
|
3
3
|
module Ddr::Utils
|
4
|
-
extend Deprecation
|
5
4
|
|
6
|
-
|
5
|
+
DEFAULT_MIME_TYPE = "application/octet-stream"
|
6
|
+
|
7
|
+
def self.digest(content, algorithm)
|
7
8
|
raise TypeError, "Algorithm must be a string: #{algorithm.inspect}" unless algorithm.is_a?(String)
|
8
9
|
digest_class = OpenSSL::Digest.const_get(algorithm.sub("-", "").to_sym)
|
9
10
|
digest_class.new(content).to_s
|
@@ -13,11 +14,12 @@ module Ddr::Utils
|
|
13
14
|
|
14
15
|
# Return a mime type for the file, using the file_name if necessary
|
15
16
|
# file can be a File object or file path (String)
|
16
|
-
#
|
17
|
+
# Return default mime type if unable to determine otherwise
|
17
18
|
def self.mime_type_for(file, file_name=nil)
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
return file.content_type if file.respond_to?(:content_type) # E.g., Rails uploaded file
|
20
|
+
path = file_name || file_path(file) rescue nil
|
21
|
+
mime_types = MIME::Types.of(path) rescue [] # MIME::Types.of blows up on nil
|
22
|
+
mime_types.empty? ? DEFAULT_MIME_TYPE : mime_types.first.content_type
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.file_or_path?(file)
|
@@ -28,7 +30,7 @@ module Ddr::Utils
|
|
28
30
|
|
29
31
|
def self.file_path?(file)
|
30
32
|
# length is a sanity check
|
31
|
-
file.is_a?(String) && (file.length < 1024) && File.
|
33
|
+
file.is_a?(String) && (file.length < 1024) && File.exists?(file)
|
32
34
|
end
|
33
35
|
|
34
36
|
def self.file_path(file)
|
@@ -37,16 +39,13 @@ module Ddr::Utils
|
|
37
39
|
elsif file_path?(file)
|
38
40
|
file
|
39
41
|
else
|
40
|
-
raise ArgumentError, "
|
42
|
+
raise ArgumentError, "File argument is neither a File nor a path to an existing file."
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
def self.file_name_for(file)
|
45
|
-
if file.respond_to?(:original_filename) && file.original_filename.present?
|
46
|
-
|
47
|
-
else
|
48
|
-
File.basename file_path(file)
|
49
|
-
end
|
47
|
+
return file.original_filename if file.respond_to?(:original_filename) && file.original_filename.present?
|
48
|
+
File.basename(file_path(file)) rescue nil
|
50
49
|
end
|
51
50
|
|
52
51
|
def self.file_uri?(uri)
|
@@ -64,23 +63,15 @@ module Ddr::Utils
|
|
64
63
|
# Return file path for URI string
|
65
64
|
# Should reverse .path_to_uri
|
66
65
|
# "file:/path/to/file" => "/path/to/file"
|
67
|
-
|
68
|
-
|
69
|
-
def self.path_from_uri(uri_string)
|
70
|
-
uri = URI.parse(uri_string)
|
71
|
-
unless uri.scheme == "file"
|
72
|
-
raise ArgumentError, "URI does not have the file: scheme."
|
73
|
-
end
|
74
|
-
URI.unescape(uri.path)
|
66
|
+
def self.path_from_uri(uri)
|
67
|
+
URI.unescape(URI.parse(uri).path)
|
75
68
|
end
|
76
69
|
|
77
70
|
# Return URI string for file path
|
78
71
|
# Should reverse .path_from_uri
|
79
72
|
# "/path/to/file" => "file:/path/to/file"
|
80
|
-
# @param path [String] the file path
|
81
|
-
# @return [String] the file: URI string
|
82
73
|
def self.path_to_uri(path)
|
83
|
-
uri = URI.parse
|
74
|
+
uri = URI.parse(URI.escape(path))
|
84
75
|
uri.scheme = "file"
|
85
76
|
uri.to_s
|
86
77
|
end
|
@@ -178,8 +169,4 @@ module Ddr::Utils
|
|
178
169
|
dts.map { |dt| solr_date(dt) }
|
179
170
|
end
|
180
171
|
|
181
|
-
class << self
|
182
|
-
alias_method :file_name, :file_name_for
|
183
|
-
end
|
184
|
-
|
185
172
|
end
|
data/lib/ddr/vocab.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
require "rdf/vocab"
|
2
2
|
|
3
|
-
module Ddr
|
4
|
-
|
3
|
+
module Ddr
|
4
|
+
module Vocab
|
5
|
+
extend ActiveSupport::Autoload
|
5
6
|
|
6
|
-
|
7
|
+
BASE_URI = "http://repository.lib.duke.edu/vocab"
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
PREMIS = begin
|
10
|
+
RDF::Vocab::PREMIS::V1
|
11
|
+
rescue NameError
|
12
|
+
RDF::Vocab::PREMIS
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
autoload :Asset
|
16
|
+
autoload :Contact
|
17
|
+
autoload :Display
|
18
|
+
autoload :DukeTerms
|
19
|
+
autoload :RDFVocabularyParser
|
20
|
+
autoload :Roles
|
21
|
+
autoload :Vocabulary
|
21
22
|
|
23
|
+
end
|
22
24
|
end
|
data/lib/ddr/vocab/asset.rb
CHANGED
@@ -1,51 +1,26 @@
|
|
1
|
-
module Ddr
|
2
|
-
|
1
|
+
module Ddr
|
2
|
+
module Vocab
|
3
|
+
class Asset < RDF::StrictVocabulary("http://repository.lib.duke.edu/vocab/asset/")
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
property "permanentId",
|
6
|
+
label: "Permanent Identifier"
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
property "permanentUrl",
|
9
|
+
label: "Permanent URL"
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
property "workflowState",
|
12
|
+
label: "Workflow State"
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
property "adminSet",
|
15
|
+
label: "Administrative Set",
|
16
|
+
comment: "A name under which objects (principally collections) are grouped for administrative purposes."
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
property "eadId",
|
19
|
+
label: "EAD ID"
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
property "isLocked",
|
24
|
-
label: "Is Locked?"
|
25
|
-
|
26
|
-
property "ingestedBy",
|
27
|
-
label: "Ingested By",
|
28
|
-
comment: "The agent (person or software) that initiated or performed the ingestion of the object."
|
29
|
-
|
30
|
-
property "ingestionDate",
|
31
|
-
label: "Ingestion Date",
|
32
|
-
comment: "The date/time at which the object was originally ingested into the repository."
|
33
|
-
|
34
|
-
property "rightsNote",
|
35
|
-
label: "Rights Note",
|
36
|
-
comment: "Free-text statement about the rights status of the resource."
|
37
|
-
|
38
|
-
property "alephId",
|
39
|
-
label: "Aleph ID",
|
40
|
-
comment: "The Aleph identifier for a catalog record corresponding to the object."
|
41
|
-
|
42
|
-
property "affiliation",
|
43
|
-
label: "Affiliation",
|
44
|
-
comment: "An organizational entity associated with the object content."
|
45
|
-
|
46
|
-
property "nestedPath",
|
47
|
-
label: "Nested Path",
|
48
|
-
comment: "The nested/tree path to the object to be reflected in structural metadata."
|
21
|
+
property "multiresImageFilePath",
|
22
|
+
label: "Multires Image File Path"
|
49
23
|
|
24
|
+
end
|
50
25
|
end
|
51
26
|
end
|