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
@@ -1,110 +1,50 @@
|
|
1
|
-
require "virtus"
|
2
|
-
|
3
1
|
module Ddr::Index
|
4
2
|
class QueryClause
|
5
|
-
include Virtus.value_object
|
6
|
-
|
7
|
-
ANY_FIELD = Field.new('*').freeze
|
8
|
-
ANY_VALUE = "[* TO *]"
|
9
|
-
QUOTE = '"'
|
10
|
-
|
11
|
-
TERM_QUERY = "{!term f=%{field}}%{value}"
|
12
|
-
STANDARD_QUERY = "%{field}:%{value}"
|
13
|
-
NEGATIVE_QUERY = "-%{field}:%{value}"
|
14
|
-
DISJUNCTION = "{!lucene q.op=OR df=%{field}}%{value}"
|
15
|
-
REGEXP_QUERY = "%{field}:/%{value}/"
|
16
|
-
|
17
|
-
values do
|
18
|
-
attribute :field, FieldAttribute
|
19
|
-
attribute :value, String
|
20
|
-
attribute :quote_value, Boolean, default: false
|
21
|
-
attribute :template, String, default: STANDARD_QUERY
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_s
|
25
|
-
template % { field: field, value: quote_value ? quote(value) : value }
|
26
|
-
end
|
27
3
|
|
28
|
-
|
29
|
-
|
30
|
-
|
4
|
+
PRESENT = "[* TO *]"
|
5
|
+
TERM = "{!term f=%s}%s"
|
6
|
+
BEFORE_DAYS = "[* TO NOW-%sDAYS]"
|
31
7
|
|
32
8
|
class << self
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
QUOTE + value.gsub("'", "\\\\\'").gsub('"', "\\\\\"") + QUOTE
|
37
|
-
else
|
38
|
-
value
|
39
|
-
end
|
9
|
+
# Standard Solr query, no escaping applied
|
10
|
+
def build(field, value)
|
11
|
+
[field, value].join(":")
|
40
12
|
end
|
41
13
|
|
42
|
-
# Builds a query clause to retrieve the index document by unique key.
|
43
14
|
def unique_key(value)
|
44
15
|
term(UniqueKeyField.instance, value)
|
45
16
|
end
|
46
17
|
alias_method :id, :unique_key
|
18
|
+
alias_method :pid, :unique_key
|
47
19
|
|
48
|
-
def where(field, value)
|
49
|
-
values = Array(value)
|
50
|
-
if values.size > 1
|
51
|
-
disjunction(field, values)
|
52
|
-
else
|
53
|
-
new(field: field, value: values.first, quote_value: true)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Builds a query clause to filter where field does not have the given value.
|
58
20
|
def negative(field, value)
|
59
|
-
|
21
|
+
build "-#{field}", value
|
60
22
|
end
|
61
23
|
|
62
|
-
# Builds a query clause to filter where field is present (i.e, has any value)
|
63
24
|
def present(field)
|
64
|
-
|
25
|
+
build field, PRESENT
|
65
26
|
end
|
66
27
|
|
67
|
-
# Builds a query clause to filter where field is NOT present (no values)
|
68
28
|
def absent(field)
|
69
|
-
|
29
|
+
negative field, PRESENT
|
70
30
|
end
|
71
31
|
|
72
|
-
|
73
|
-
|
74
|
-
value = values.map { |v| quote(v) }.join(" ")
|
75
|
-
new(field: field, value: value, template: DISJUNCTION)
|
32
|
+
def or_values(field, *values)
|
33
|
+
build field, QueryValue.or_values(*values)
|
76
34
|
end
|
77
35
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
field, value = where.to_a.first
|
82
|
-
from_field = FieldAttribute.coerce(from)
|
83
|
-
to_field = FieldAttribute.coerce(to)
|
84
|
-
template = "{!join from=#{from_field} to=#{to_field}}%{field}:%{value}"
|
85
|
-
new(field: field, value: value, template: template, quote_value: true)
|
36
|
+
def before(field, date_time)
|
37
|
+
value = "[* TO %s]" % Ddr::Utils.solr_date(date_time)
|
38
|
+
build field, value
|
86
39
|
end
|
87
40
|
|
88
|
-
|
89
|
-
|
90
|
-
|
41
|
+
def before_days(field, days)
|
42
|
+
value = BEFORE_DAYS % days.to_i
|
43
|
+
build field, value
|
91
44
|
end
|
92
|
-
alias_method :before_date_time, :before
|
93
45
|
|
94
|
-
# Builds a query clause to filter where date field value is earlier than a number of days before now.
|
95
|
-
def before_days(field, value)
|
96
|
-
new(field: field, value: "[* TO NOW-%iDAYS]" % value)
|
97
|
-
end
|
98
|
-
|
99
|
-
# Builds a "term query" clause to filter where field contains value.
|
100
46
|
def term(field, value)
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
# Builds a regular expression query clause
|
105
|
-
def regexp(field, value)
|
106
|
-
val = value.gsub(/\//, "\\/")
|
107
|
-
new(field: field, value: val, template: REGEXP_QUERY)
|
47
|
+
TERM % [field, value.gsub(/"/, '\"')]
|
108
48
|
end
|
109
49
|
end
|
110
50
|
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Ddr::Index
|
2
2
|
class QueryResult < AbstractQueryResult
|
3
|
-
extend Deprecation
|
4
3
|
|
5
4
|
PAGE_SIZE = 1000
|
6
5
|
|
@@ -15,7 +14,7 @@ module Ddr::Index
|
|
15
14
|
end
|
16
15
|
|
17
16
|
def each_unpaginated(&block)
|
18
|
-
|
17
|
+
conn.select(params).docs.each(&block)
|
19
18
|
end
|
20
19
|
|
21
20
|
def each_paginated(&block)
|
@@ -23,31 +22,15 @@ module Ddr::Index
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def pids
|
26
|
-
Deprecation.warn(QueryResult,
|
27
|
-
"`pids` is deprecated; use `ids` instead." \
|
28
|
-
" (called from #{caller.first})"
|
29
|
-
)
|
30
|
-
ids
|
31
|
-
end
|
32
|
-
|
33
|
-
def ids
|
34
25
|
Enumerator.new do |e|
|
35
26
|
each do |doc|
|
36
|
-
e << doc[Fields::
|
27
|
+
e << doc[Fields::PID]
|
37
28
|
end
|
38
29
|
end
|
39
30
|
end
|
40
31
|
|
41
32
|
def each_pid(&block)
|
42
|
-
|
43
|
-
"`each_pid` is deprecated; use `each_id` instead." \
|
44
|
-
" (called from #{caller.first})"
|
45
|
-
)
|
46
|
-
each_id(&block)
|
47
|
-
end
|
48
|
-
|
49
|
-
def each_id(&block)
|
50
|
-
ids.each(&block)
|
33
|
+
pids.each(&block)
|
51
34
|
end
|
52
35
|
|
53
36
|
def docs
|
@@ -58,21 +41,6 @@ module Ddr::Index
|
|
58
41
|
end
|
59
42
|
end
|
60
43
|
|
61
|
-
def objects
|
62
|
-
Enumerator.new do |e|
|
63
|
-
each_id do |id|
|
64
|
-
e << ActiveFedora::Base.find(id)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def facet_fields
|
70
|
-
response = Connection.select(params, rows: 0)
|
71
|
-
response.facet_fields.each_with_object({}) do |(field, values), memo|
|
72
|
-
memo[field] = Hash[*values]
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
44
|
def all
|
77
45
|
to_a
|
78
46
|
end
|
@@ -94,7 +62,7 @@ module Ddr::Index
|
|
94
62
|
def page(num)
|
95
63
|
page_params = params.dup
|
96
64
|
page_size = page_params.delete(:rows) || PAGE_SIZE
|
97
|
-
response =
|
65
|
+
response = conn.page num, page_size, "select", params: page_params
|
98
66
|
response.docs
|
99
67
|
end
|
100
68
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rsolr"
|
2
|
+
|
3
|
+
module Ddr::Index
|
4
|
+
class QueryValue
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def build(value)
|
8
|
+
RSolr.solr_escape(value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def or_values(*values)
|
12
|
+
value = values.map { |v| build(v) }.join(" OR ")
|
13
|
+
"(#{value})"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/ddr/index/response.rb
CHANGED
@@ -1,29 +1,12 @@
|
|
1
|
-
require "delegate"
|
2
|
-
|
3
1
|
module Ddr::Index
|
4
|
-
#
|
5
|
-
# Wraps an index query response
|
6
|
-
#
|
7
2
|
class Response < SimpleDelegator
|
8
3
|
|
9
4
|
def docs
|
10
|
-
response["docs"]
|
5
|
+
self["response"]["docs"]
|
11
6
|
end
|
12
7
|
|
13
8
|
def num_found
|
14
|
-
response["numFound"].to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
def facet_counts
|
18
|
-
self["facet_counts"] || {}
|
19
|
-
end
|
20
|
-
|
21
|
-
def facet_fields
|
22
|
-
facet_counts["facet_fields"] || {}
|
23
|
-
end
|
24
|
-
|
25
|
-
def response
|
26
|
-
self["response"]
|
9
|
+
self["response"]["numFound"].to_i
|
27
10
|
end
|
28
11
|
|
29
12
|
end
|
data/lib/ddr/jobs.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Ddr::Jobs
|
4
|
+
class FitsFileCharacterization
|
5
|
+
|
6
|
+
@queue = :file_characterization
|
7
|
+
|
8
|
+
EVENT_SUMMARY = 'FITS characterization of content file'.freeze
|
9
|
+
|
10
|
+
def self.perform(pid)
|
11
|
+
obj = ActiveFedora::Base.find(pid)
|
12
|
+
tmp_filename = Ddr::Utils::sanitize_filename(obj.original_filename) || obj.content.default_file_name
|
13
|
+
Dir.mktmpdir do |dir|
|
14
|
+
infile = create_temp_infile(dir, tmp_filename, obj.content.content)
|
15
|
+
fits_output, err, status = Open3.capture3(fits_command, '-i', infile)
|
16
|
+
if status.success? && fits_output.present?
|
17
|
+
obj.reload
|
18
|
+
obj.fits.content = fits_output
|
19
|
+
obj.save!
|
20
|
+
end
|
21
|
+
notify_event(pid, err, status)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.fits_command
|
26
|
+
File.join(Ddr::Models.fits_home, 'fits.sh')
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.fits_version
|
30
|
+
`#{fits_command} -v`.strip
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def self.create_temp_infile(dir, tmp_filename, content)
|
36
|
+
temp_infile = File.join(dir, tmp_filename)
|
37
|
+
File.open(temp_infile, 'wb') do |f|
|
38
|
+
f.write content
|
39
|
+
end
|
40
|
+
temp_infile
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.notify_event(pid, err, status)
|
44
|
+
details = status.success? ? nil : err
|
45
|
+
event_args = { pid: pid, summary: EVENT_SUMMARY, software: "fits #{fits_version}", detail: details }
|
46
|
+
event_args[:outcome] = status.success? ? Ddr::Events::Event::SUCCESS : Ddr::Events::Event::FAILURE
|
47
|
+
Ddr::Notifications.notify_event(:update, event_args)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "ezid-client"
|
2
|
+
|
3
|
+
module Ddr
|
4
|
+
module Jobs
|
5
|
+
module PermanentId
|
6
|
+
|
7
|
+
class Job
|
8
|
+
def self.inherited(subclass)
|
9
|
+
subclass.instance_variable_set("@queue", :permanent_id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class MakeUnavailable < Job
|
14
|
+
def self.perform(id, reason = nil)
|
15
|
+
identifier = Ezid::Identifier.find(id)
|
16
|
+
identifier.unavailable!(reason)
|
17
|
+
identifier.save
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/ddr/managers.rb
CHANGED
@@ -1,115 +1,75 @@
|
|
1
1
|
require "resque"
|
2
2
|
|
3
|
-
module Ddr
|
4
|
-
|
5
|
-
|
3
|
+
module Ddr
|
4
|
+
module Managers
|
5
|
+
class DerivativesManager < Manager
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
SCHEDULE_LATER = :later
|
8
|
+
SCHEDULE_NOW = :now
|
9
|
+
SCHEDULES = [ SCHEDULE_LATER, SCHEDULE_NOW ]
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
ACTION_DELETE = "delete"
|
12
|
+
ACTION_GENERATE = "generate"
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
(object.datastreams[derivative.datastream].has_content? || generatable?(derivative))
|
24
|
-
schedule == SCHEDULE_NOW ? update_derivative(derivative) : Resque.enqueue(DerivativeJob, object.pid, derivative.name)
|
14
|
+
def update_derivatives(schedule=SCHEDULE_LATER)
|
15
|
+
raise ArgumentError, "Must be one of #{SCHEDULES}" unless SCHEDULES.include?(schedule)
|
16
|
+
Ddr::Derivatives.update_derivatives.each do |derivative_to_update|
|
17
|
+
derivative = Ddr::Derivatives::DERIVATIVES[derivative_to_update]
|
18
|
+
# Need to update derivative if either (or both) of the following conditions are true:
|
19
|
+
# - object already has this derivative (need to delete or replace it)
|
20
|
+
# - the derivative can be generated for this object
|
21
|
+
if derivative.class.has_derivative?(object) || derivative.class.generatable?(object)
|
22
|
+
schedule == SCHEDULE_NOW ? update_derivative(derivative) : Resque.enqueue(DerivativeJob, object.pid, derivative_to_update)
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
28
|
-
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
delete_derivative derivative
|
27
|
+
def update_derivative(derivative)
|
28
|
+
if derivative.class.generatable?(object)
|
29
|
+
generate_derivative(derivative)
|
30
|
+
else
|
31
|
+
# Delete existing derivative (if there is one) if that type of derivative is no longer
|
32
|
+
# applicable to the object
|
33
|
+
if derivative.class.has_derivative?(object)
|
34
|
+
delete_derivative(derivative)
|
35
|
+
end
|
40
36
|
end
|
41
37
|
end
|
42
|
-
end
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
generator_output_path = File.new(File.join(tempdir, "output.out"), 'wb').path
|
51
|
-
exitstatus = derivative.generator.new(generator_source_path, generator_output_path, derivative.options).generate
|
52
|
-
if exitstatus == 0
|
53
|
-
generator_output = File.open(generator_output_path, 'rb')
|
54
|
-
object.reload if object.persisted?
|
55
|
-
object.add_file generator_output, derivative.datastream, mime_type: derivative.generator.output_mime_type
|
56
|
-
object.save!
|
57
|
-
else
|
58
|
-
raise Ddr::Models::DerivativeGenerationFailure,
|
59
|
-
"Failure generating #{derivative.name} for #{object.pid}"
|
39
|
+
def generate_derivative(derivative)
|
40
|
+
ActiveSupport::Notifications.instrument(Ddr::Notifications::UPDATE,
|
41
|
+
pid: object.pid,
|
42
|
+
summary: "Generate #{derivative.class.name} derivative"
|
43
|
+
) do |payload|
|
44
|
+
derivative.generate!(object)
|
60
45
|
end
|
61
|
-
generator_output.close unless generator_output.closed?
|
62
|
-
ensure
|
63
|
-
FileUtils.remove_dir(tempdir_path) if File.exist?(tempdir_path)
|
64
46
|
end
|
65
|
-
end
|
66
|
-
|
67
|
-
alias_method :generate_derivative, :generate_derivative!
|
68
|
-
|
69
|
-
def delete_derivative!(derivative)
|
70
|
-
File.unlink *object.datastreams[derivative.datastream].file_paths if
|
71
|
-
object.datastreams[derivative.datastream].external?
|
72
|
-
object.datastreams[derivative.datastream].delete
|
73
|
-
object.save!
|
74
|
-
end
|
75
|
-
|
76
|
-
alias_method :delete_derivative, :delete_derivative!
|
77
47
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
def self.perform(pid, derivative_name)
|
86
|
-
object = ActiveFedora::Base.find(pid)
|
87
|
-
derivative = Ddr::Derivatives::DERIVATIVES[derivative_name.to_sym]
|
88
|
-
object.derivatives.update_derivative(derivative)
|
48
|
+
def delete_derivative(derivative)
|
49
|
+
ActiveSupport::Notifications.instrument(Ddr::Notifications::UPDATE,
|
50
|
+
pid: object.pid,
|
51
|
+
summary: "Delete derivative #{derivative.class.name}"
|
52
|
+
) do |payload|
|
53
|
+
derivative.delete!(object)
|
54
|
+
end
|
89
55
|
end
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
56
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
57
|
+
def delete_derivative!(derivative)
|
58
|
+
File.unlink *object.datastreams[derivative.datastream].file_paths if
|
59
|
+
object.datastreams[derivative.datastream].external?
|
60
|
+
object.datastreams[derivative.datastream].delete
|
61
|
+
object.save!
|
62
|
+
end
|
101
63
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
else
|
110
|
-
false
|
64
|
+
class DerivativeJob
|
65
|
+
@queue = :derivatives
|
66
|
+
def self.perform(pid, derivative_name)
|
67
|
+
object = ActiveFedora::Base.find(pid)
|
68
|
+
derivative = Ddr::Derivatives::DERIVATIVES[derivative_name.to_sym]
|
69
|
+
object.derivatives.update_derivative(derivative)
|
70
|
+
end
|
111
71
|
end
|
112
|
-
end
|
113
72
|
|
73
|
+
end
|
114
74
|
end
|
115
75
|
end
|