hyrax 3.0.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +46 -13
- data/.dassie/Gemfile +11 -6
- data/.dassie/app/controllers/catalog_controller.rb +6 -0
- data/.dassie/config/initializers/hyrax.rb +5 -0
- data/.dassie/config/initializers/riiif.rb +22 -20
- data/.dassie/config/role_map.yml +2 -0
- data/.dassie/db/seeds.rb +1 -1
- data/.dassie/package.json +3 -5
- data/.dockerignore +3 -0
- data/.env +1 -2
- data/.rubocop.yml +4 -0
- data/CONTAINERS.md +21 -1
- data/Dockerfile +42 -17
- data/Gemfile +21 -27
- data/app/actors/hyrax/actors/base_actor.rb +2 -2
- data/app/actors/hyrax/actors/collections_membership_actor.rb +3 -3
- data/app/actors/hyrax/actors/create_with_remote_files_actor.rb +85 -63
- data/app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb +7 -42
- data/app/actors/hyrax/actors/file_set_actor.rb +12 -5
- data/app/assets/stylesheets/hyrax/_styles.scss +5 -0
- data/app/controllers/concerns/hyrax/collections_controller_behavior.rb +30 -10
- data/app/controllers/concerns/hyrax/controller.rb +13 -2
- data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +21 -9
- data/app/controllers/concerns/hyrax/leases_controller_behavior.rb +14 -5
- data/app/controllers/concerns/hyrax/works_controller_behavior.rb +22 -3
- data/app/controllers/hyrax/admin/admin_sets_controller.rb +2 -19
- data/app/controllers/hyrax/admin/permission_template_accesses_controller.rb +5 -6
- data/app/controllers/hyrax/admin/workflows_controller.rb +8 -2
- data/app/controllers/hyrax/collections_controller.rb +3 -1
- data/app/controllers/hyrax/dashboard/collection_members_controller.rb +24 -17
- data/app/controllers/hyrax/dashboard/collections_controller.rb +99 -35
- data/app/controllers/hyrax/dashboard/nest_collections_controller.rb +75 -39
- data/app/controllers/hyrax/file_sets_controller.rb +49 -13
- data/app/controllers/hyrax/my_controller.rb +4 -4
- data/app/controllers/hyrax/permissions_controller.rb +3 -4
- data/app/controllers/hyrax/workflow_actions_controller.rb +11 -6
- data/app/forms/hyrax/forms/administrative_set_form.rb +62 -0
- data/app/forms/hyrax/forms/collection_form.rb +14 -8
- data/app/forms/hyrax/forms/dashboard/nest_collection_form.rb +38 -6
- data/app/forms/hyrax/forms/file_set_form.rb +46 -0
- data/app/forms/hyrax/forms/pcdm_collection_form.rb +64 -0
- data/app/forms/hyrax/forms/permission.rb +23 -0
- data/app/forms/hyrax/forms/permission_template_form.rb +8 -2
- data/app/forms/hyrax/forms/resource_form.rb +34 -26
- data/app/forms/hyrax/forms/work_form.rb +5 -2
- data/app/forms/hyrax/forms/workflow_action_form.rb +4 -0
- data/app/helpers/hyrax/batch_edits_helper.rb +3 -1
- data/app/helpers/hyrax/collections_helper.rb +88 -2
- data/app/helpers/hyrax/dashboard_helper_behavior.rb +16 -5
- data/app/helpers/hyrax/embargo_helper.rb +4 -0
- data/app/helpers/hyrax/file_set_helper.rb +25 -6
- data/app/helpers/hyrax/hyrax_helper_behavior.rb +9 -0
- data/app/helpers/hyrax/lease_helper.rb +4 -0
- data/app/helpers/hyrax/url_helper.rb +4 -1
- data/app/helpers/hyrax/work_form_helper.rb +53 -0
- data/app/indexers/hyrax/administrative_set_indexer.rb +18 -0
- data/app/indexers/hyrax/pcdm_collection_indexer.rb +2 -0
- data/app/indexers/hyrax/valkyrie_file_set_indexer.rb +2 -0
- data/app/indexers/hyrax/valkyrie_indexer.rb +4 -3
- data/app/indexers/hyrax/valkyrie_work_indexer.rb +1 -1
- data/app/inputs/controlled_vocabulary_input.rb +2 -5
- data/app/jobs/attach_files_to_work_job.rb +19 -10
- data/app/jobs/attach_files_to_work_with_ordered_members_job.rb +6 -5
- data/app/jobs/ingest_local_file_job.rb +18 -2
- data/app/jobs/inherit_permissions_job.rb +9 -5
- data/app/models/admin_set.rb +22 -30
- data/app/models/collection_branding_info.rb +25 -9
- data/app/models/concerns/hyrax/ability/admin_set_ability.rb +31 -7
- data/app/models/concerns/hyrax/ability/collection_ability.rb +35 -20
- data/app/models/concerns/hyrax/ability/collection_type_ability.rb +1 -1
- data/app/models/concerns/hyrax/ability.rb +5 -3
- data/app/models/concerns/hyrax/collection_behavior.rb +17 -44
- data/app/models/concerns/hyrax/embargoable.rb +24 -0
- data/app/models/concerns/hyrax/file_set/characterization.rb +18 -12
- data/app/models/concerns/hyrax/solr_document_behavior.rb +11 -54
- data/app/models/concerns/hyrax/suppressible.rb +5 -0
- data/app/models/concerns/hyrax/user.rb +9 -3
- data/app/models/concerns/hyrax/work_behavior.rb +1 -1
- data/app/models/hyrax/administrative_set.rb +7 -1
- data/app/models/hyrax/file_set.rb +6 -0
- data/app/models/hyrax/pcdm_collection.rb +1 -0
- data/app/models/hyrax/permission.rb +1 -1
- data/app/models/hyrax/permission_template.rb +112 -12
- data/app/models/hyrax/virus_scanner.rb +27 -18
- data/app/models/hyrax/work.rb +1 -0
- data/app/models/hyrax/workflow_action_info.rb +16 -0
- data/app/models/sipity/agent.rb +1 -0
- data/app/models/sipity/comment.rb +17 -0
- data/app/models/sipity/entity.rb +30 -8
- data/app/models/sipity/workflow.rb +1 -0
- data/app/models/sipity.rb +53 -2
- data/app/presenters/hyrax/admin_set_options_presenter.rb +12 -8
- data/app/presenters/hyrax/admin_set_presenter.rb +13 -4
- data/app/presenters/hyrax/admin_set_selection_presenter.rb +116 -0
- data/app/presenters/hyrax/collection_presenter.rb +44 -23
- data/app/presenters/hyrax/file_set_presenter.rb +6 -1
- data/app/presenters/hyrax/file_usage.rb +3 -2
- data/app/presenters/hyrax/pcdm_member_presenter_factory.rb +119 -0
- data/app/presenters/hyrax/stats_usage_presenter.rb +2 -1
- data/app/presenters/hyrax/trophy_presenter.rb +33 -4
- data/app/presenters/hyrax/user_profile_presenter.rb +11 -1
- data/app/presenters/hyrax/version_list_presenter.rb +19 -0
- data/app/presenters/hyrax/version_presenter.rb +3 -2
- data/app/presenters/hyrax/work_show_presenter.rb +32 -6
- data/app/presenters/hyrax/work_usage.rb +5 -3
- data/app/renderers/hyrax/renderers/attribute_renderer.rb +10 -2
- data/app/search_builders/hyrax/abstract_type_relation.rb +4 -2
- data/app/search_builders/hyrax/admin_set_search_builder.rb +1 -1
- data/app/search_builders/hyrax/collection_member_search_builder.rb +6 -1
- data/app/search_builders/hyrax/dashboard/collections_search_builder.rb +1 -1
- data/app/search_builders/hyrax/exposed_models_relation.rb +1 -1
- data/app/search_builders/hyrax/filter_by_type.rb +1 -2
- data/app/search_builders/hyrax/my/collections_search_builder.rb +2 -2
- data/app/search_builders/hyrax/nested_collections_parent_search_builder.rb +1 -1
- data/app/search_builders/hyrax/single_collection_search_builder.rb +1 -1
- data/app/services/hyrax/admin_set_create_service.rb +136 -52
- data/app/services/hyrax/collection_types/permissions_service.rb +1 -1
- data/app/services/hyrax/collections/collection_member_search_service.rb +72 -0
- data/app/services/hyrax/collections/collection_member_service.rb +122 -27
- data/app/services/hyrax/collections/migration_service.rb +4 -2
- data/app/services/hyrax/collections/nested_collection_persistence_service.rb +12 -13
- data/app/services/hyrax/collections/nested_collection_query_service.rb +2 -0
- data/app/services/hyrax/collections/permissions_create_service.rb +82 -78
- data/app/services/hyrax/collections/permissions_service.rb +1 -1
- data/app/services/hyrax/contextual_path.rb +24 -1
- data/app/services/hyrax/curation_concern.rb +24 -2
- data/app/services/hyrax/custom_queries/find_file_metadata.rb +7 -5
- data/app/services/hyrax/custom_queries/navigators/parent_collections_navigator.rb +46 -0
- data/app/services/hyrax/default_middleware_stack.rb +11 -0
- data/app/services/hyrax/edit_permissions_service.rb +74 -41
- data/app/services/hyrax/ensure_well_formed_admin_set_service.rb +3 -3
- data/app/services/hyrax/find_objects_via_solr_service.rb +31 -0
- data/app/services/hyrax/listeners/active_fedora_acl_index_listener.rb +1 -0
- data/app/services/hyrax/listeners/member_cleanup_listener.rb +26 -0
- data/app/services/hyrax/listeners/metadata_index_listener.rb +25 -9
- data/app/services/hyrax/listeners/object_lifecycle_listener.rb +1 -1
- data/app/services/hyrax/listeners/trophy_cleanup_listener.rb +17 -0
- data/app/services/hyrax/listeners.rb +2 -0
- data/app/services/hyrax/multiple_membership_checker.rb +53 -29
- data/app/services/hyrax/permission_manager.rb +4 -4
- data/app/services/hyrax/persist_derivatives.rb +3 -1
- data/app/services/hyrax/resource_status.rb +7 -0
- data/app/services/hyrax/search_service.rb +4 -2
- data/app/services/hyrax/solr_query_builder_service.rb +45 -8
- data/app/services/hyrax/solr_query_service.rb +224 -0
- data/app/services/hyrax/solr_service.rb +9 -2
- data/app/services/hyrax/statistics/collections/over_time.rb +2 -1
- data/app/services/hyrax/statistics/depositors/summary.rb +2 -1
- data/app/services/hyrax/thumbnail_path_service.rb +1 -1
- data/app/services/hyrax/visibility_intention.rb +20 -2
- data/app/services/hyrax/visibility_propagator.rb +30 -1
- data/app/services/hyrax/work_uploads_handler.rb +17 -2
- data/app/services/hyrax/workflow/abstract_notification.rb +2 -2
- data/app/services/hyrax/workflow/action_taken_service.rb +16 -4
- data/app/services/hyrax/workflow/actionable_objects.rb +70 -0
- data/app/services/hyrax/workflow/activate_object.rb +5 -4
- data/app/services/hyrax/workflow/changes_required_notification.rb +5 -4
- data/app/services/hyrax/workflow/deactivate_object.rb +7 -5
- data/app/services/hyrax/workflow/deposited_notification.rb +8 -4
- data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +7 -3
- data/app/services/hyrax/workflow/grant_read_to_depositor.rb +10 -3
- data/app/services/hyrax/workflow/object_in_workflow_decorator.rb +31 -0
- data/app/services/hyrax/workflow/revoke_edit_from_depositor.rb +8 -2
- data/app/services/hyrax/workflow/status_list_service.rb +43 -13
- data/app/services/hyrax/workflow/workflow_action_service.rb +4 -1
- data/app/views/hyrax/admin/admin_sets/_form.html.erb +1 -1
- data/app/views/hyrax/base/_form_child_work_relationships.html.erb +1 -1
- data/app/views/hyrax/base/_form_relationships.html.erb +1 -2
- data/app/views/hyrax/base/_form_rendering.html.erb +1 -1
- data/app/views/hyrax/base/_form_representative.html.erb +1 -1
- data/app/views/hyrax/base/_form_thumbnail.html.erb +1 -1
- data/app/views/hyrax/base/_form_visibility_error.html.erb +2 -0
- data/app/views/hyrax/base/_guts4form.html.erb +3 -3
- data/app/views/hyrax/base/_representative_media.html.erb +1 -1
- data/app/views/hyrax/base/_show_actions.html.erb +2 -2
- data/app/views/hyrax/base/_work_button_row.html.erb +1 -1
- data/app/views/hyrax/batch_uploads/_form.html.erb +1 -1
- data/app/views/hyrax/collections/show.html.erb +1 -1
- data/app/views/hyrax/dashboard/collections/_collection_title.html.erb +1 -1
- data/app/views/hyrax/dashboard/collections/_form.html.erb +4 -4
- data/app/views/hyrax/dashboard/collections/_form_branding.html.erb +1 -1
- data/app/views/hyrax/dashboard/collections/_list_collections.html.erb +1 -1
- data/app/views/hyrax/dashboard/collections/_sort_and_per_page.html.erb +1 -1
- data/app/views/hyrax/dashboard/collections/edit.html.erb +4 -2
- data/app/views/hyrax/dashboard/collections/new.html.erb +4 -2
- data/app/views/hyrax/dashboard/collections/show.html.erb +1 -1
- data/app/views/hyrax/file_sets/_actions.html.erb +10 -0
- data/app/views/hyrax/file_sets/edit.html.erb +1 -1
- data/app/views/hyrax/file_sets/media_display/_audio.html.erb +1 -1
- data/app/views/hyrax/file_sets/media_display/_default.html.erb +1 -1
- data/app/views/hyrax/file_sets/media_display/_image.html.erb +1 -1
- data/app/views/hyrax/file_sets/media_display/_office_document.html.erb +1 -1
- data/app/views/hyrax/file_sets/media_display/_pdf.html.erb +1 -1
- data/app/views/hyrax/file_sets/media_display/_video.html.erb +1 -1
- data/app/views/hyrax/file_sets/show.html.erb +1 -1
- data/app/views/hyrax/homepage/index.html.erb +1 -1
- data/app/views/hyrax/my/_admin_set_action_menu.html.erb +0 -11
- data/app/views/hyrax/my/_collection_action_menu.html.erb +1 -2
- data/app/views/hyrax/my/collections/_list_collections.html.erb +1 -1
- data/app/views/hyrax/my/collections/_modal_add_subcollection.html.erb +3 -5
- data/app/views/hyrax/my/collections/_modal_collection_types_to_create.html.erb +1 -1
- data/app/views/layouts/hyrax/dashboard.html.erb +1 -0
- data/app/views/layouts/hyrax.html.erb +1 -0
- data/app/views/shared/_read_only.html.erb +5 -0
- data/bin/db-migrate-seed.sh +3 -1
- data/bin/hyrax-entrypoint.sh +0 -14
- data/bin/solrcloud-assign-configset.sh +11 -3
- data/bin/solrcloud-upload-configset.sh +17 -6
- data/chart/hyrax/Chart.yaml +9 -5
- data/chart/hyrax/README.md +52 -5
- data/chart/hyrax/templates/_helpers.tpl +23 -1
- data/chart/hyrax/templates/branding-pvc.yaml +14 -0
- data/chart/hyrax/templates/configmap-env.yaml +14 -3
- data/chart/hyrax/templates/deployment-worker.yaml +129 -0
- data/chart/hyrax/templates/deployment.yaml +95 -0
- data/chart/hyrax/templates/derivatives-pvc.yaml +14 -0
- data/chart/hyrax/templates/ingress.yaml +13 -4
- data/chart/hyrax/templates/secrets.yaml +9 -0
- data/chart/hyrax/templates/uploads-pvc.yaml +14 -0
- data/chart/hyrax/values.yaml +114 -1
- data/config/brakeman.ignore +2 -2
- data/config/features.rb +50 -43
- data/config/initializers/1_healthz.rb +1 -0
- data/config/initializers/listeners.rb +4 -1
- data/config/initializers/valkryrie_storage.rb +7 -0
- data/config/locales/hyrax.de.yml +1 -1
- data/config/locales/hyrax.en.yml +2 -1
- data/config/locales/hyrax.es.yml +1 -1
- data/config/locales/hyrax.fr.yml +1 -1
- data/config/locales/hyrax.it.yml +1 -1
- data/config/locales/hyrax.pt-BR.yml +1 -1
- data/config/locales/hyrax.zh.yml +1 -1
- data/db/seeds.rb +1 -1
- data/docker-compose.yml +39 -8
- data/documentation/developing-your-hyrax-based-app.md +3 -3
- data/documentation/legacyREADME.md +3 -3
- data/hyrax.gemspec +1 -1
- data/lib/generators/hyrax/templates/catalog_controller.rb +3 -1
- data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +15 -0
- data/lib/generators/hyrax/templates/config/initializers/riiif.rb +22 -20
- data/lib/generators/hyrax/work/templates/feature_spec.rb.erb +1 -1
- data/lib/generators/hyrax/work_resource/templates/indexer_spec.rb.erb +1 -0
- data/lib/hyrax/active_fedora_dummy_model.rb +62 -0
- data/lib/hyrax/collection_name.rb +6 -2
- data/lib/hyrax/configuration.rb +56 -0
- data/lib/hyrax/engine.rb +3 -1
- data/lib/hyrax/errors.rb +2 -0
- data/lib/hyrax/form_fields.rb +1 -0
- data/lib/hyrax/publisher.rb +12 -0
- data/lib/hyrax/resource_name.rb +1 -0
- data/lib/hyrax/resource_sync/change_list_writer.rb +2 -2
- data/lib/hyrax/resource_sync/resource_list_writer.rb +2 -2
- data/lib/hyrax/specs/capybara.rb +5 -3
- data/lib/hyrax/specs/shared_specs/hydra_works.rb +2 -0
- data/lib/hyrax/specs/shared_specs/indexers.rb +6 -0
- data/lib/hyrax/specs/shared_specs/valkyrie_storage_versions.rb +9 -0
- data/lib/hyrax/transactions/collection_create.rb +25 -0
- data/lib/hyrax/transactions/collection_update.rb +20 -0
- data/lib/hyrax/transactions/container.rb +47 -0
- data/lib/hyrax/transactions/file_set_destroy.rb +21 -0
- data/lib/hyrax/transactions/steps/add_file_sets.rb +3 -2
- data/lib/hyrax/transactions/steps/add_to_collections.rb +13 -1
- data/lib/hyrax/transactions/steps/add_to_parent.rb +36 -0
- data/lib/hyrax/transactions/steps/apply_collection_type_permissions.rb +29 -0
- data/lib/hyrax/transactions/steps/remove_file_set_from_work.rb +47 -0
- data/lib/hyrax/transactions/steps/save.rb +18 -6
- data/lib/hyrax/transactions/steps/set_collection_type_gid.rb +35 -0
- data/lib/hyrax/transactions/work_create.rb +2 -1
- data/lib/hyrax/valkyrie_can_can_adapter.rb +3 -0
- data/lib/hyrax/valkyrie_simple_path_generator.rb +20 -0
- data/lib/hyrax/version.rb +1 -1
- data/lib/hyrax.rb +9 -0
- data/lib/tasks/collection_type_global_id.rake +1 -1
- data/lib/tasks/default_admin_set.rake +12 -11
- data/lib/tasks/regenerate_derivatives.rake +12 -0
- data/lib/wings/active_fedora_converter/default_work.rb +15 -0
- data/lib/wings/converter_value_mapper.rb +2 -2
- data/lib/wings/model_transformer.rb +17 -1
- data/lib/wings/orm_converter.rb +18 -2
- data/lib/wings/setup.rb +2 -0
- data/lib/wings/valkyrie/persister.rb +7 -5
- data/lib/wings/valkyrie/query_service.rb +60 -17
- data/lib/wings/valkyrie/storage.rb +56 -1
- data/lib/wings.rb +0 -21
- data/template.rb +1 -1
- metadata +42 -9
@@ -15,10 +15,17 @@ module Hyrax
|
|
15
15
|
# Re-index the resource.
|
16
16
|
#
|
17
17
|
# @param event [Dry::Event]
|
18
|
-
def
|
19
|
-
|
20
|
-
|
18
|
+
def on_collection_metadata_updated(event)
|
19
|
+
return unless resource? event[:collection]
|
20
|
+
Hyrax.index_adapter.save(resource: event[:collection])
|
21
|
+
end
|
21
22
|
|
23
|
+
##
|
24
|
+
# Re-index the resource.
|
25
|
+
#
|
26
|
+
# @param event [Dry::Event]
|
27
|
+
def on_object_metadata_updated(event)
|
28
|
+
return unless resource? event[:object]
|
22
29
|
Hyrax.index_adapter.save(resource: event[:object])
|
23
30
|
end
|
24
31
|
|
@@ -27,17 +34,26 @@ module Hyrax
|
|
27
34
|
#
|
28
35
|
# @param event [Dry::Event]
|
29
36
|
def on_object_deleted(event)
|
30
|
-
|
31
|
-
event.payload[:object].is_a?(Valkyrie::Resource)
|
32
|
-
|
37
|
+
return unless resource?(event.payload[:object])
|
33
38
|
Hyrax.index_adapter.delete(resource: event[:object])
|
34
39
|
end
|
35
40
|
|
36
41
|
private
|
37
42
|
|
38
|
-
def
|
39
|
-
|
40
|
-
|
43
|
+
def resource?(resource)
|
44
|
+
return true if resource.is_a? Valkyrie::Resource
|
45
|
+
log_non_resource(resource)
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def log_non_resource(resource)
|
50
|
+
generic_type = resource_generic_type(resource)
|
51
|
+
Hyrax.logger.info("Skipping #{generic_type} reindex because the " \
|
52
|
+
"#{generic_type} #{resource} was not a Valkyrie::Resource.")
|
53
|
+
end
|
54
|
+
|
55
|
+
def resource_generic_type(resource)
|
56
|
+
resource.try(:collection?) ? 'collection' : 'object'
|
41
57
|
end
|
42
58
|
end
|
43
59
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hyrax
|
4
|
+
module Listeners
|
5
|
+
##
|
6
|
+
# Listens for object deleted events and cleans up associated members
|
7
|
+
class TrophyCleanupListener
|
8
|
+
def on_object_deleted(event)
|
9
|
+
Trophy.where(work_id: event[:id]).destroy_all
|
10
|
+
rescue StandardError => err
|
11
|
+
Hyrax.logger.warn "Failed to delete trophies for #{event[:id]}. " \
|
12
|
+
'These trophies might be orphaned.' \
|
13
|
+
"\n\t#{err.message}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -14,9 +14,11 @@ module Hyrax
|
|
14
14
|
autoload :BatchNotificationListener
|
15
15
|
autoload :FileSetLifecycleListener
|
16
16
|
autoload :FileSetLifecycleNotificationListener
|
17
|
+
autoload :MemberCleanupListener
|
17
18
|
autoload :MetadataIndexListener
|
18
19
|
autoload :ObjectLifecycleListener
|
19
20
|
autoload :ProxyDepositListener
|
21
|
+
autoload :TrophyCleanupListener
|
20
22
|
autoload :WorkflowListener
|
21
23
|
end
|
22
24
|
end
|
@@ -6,8 +6,7 @@ module Hyrax
|
|
6
6
|
class MultipleMembershipChecker
|
7
7
|
attr_reader :item
|
8
8
|
|
9
|
-
# @param [#member_of_collection_ids] item an object that belongs to
|
10
|
-
# collections
|
9
|
+
# @param [#member_of_collection_ids] item an object that belongs to collections
|
11
10
|
def initialize(item:)
|
12
11
|
@item = item
|
13
12
|
end
|
@@ -20,53 +19,78 @@ module Hyrax
|
|
20
19
|
# `allow_multiple_membership` as `false` require that its members do not
|
21
20
|
# also belong to other collections of the same type.
|
22
21
|
#
|
23
|
-
# There are two contexts in which memberships are checked: when doing a
|
24
|
-
# wholesale replacement and when making an incremental change, such as
|
25
|
-
# adding a single collection membership to an object. In the former case,
|
26
|
-
# `#check` only scans the passed-in collection identifiers. In the latter,
|
27
|
-
# `#check` must also scan the collections to which an object currently
|
28
|
-
# belongs for potential conflicts.
|
29
|
-
#
|
30
22
|
# @param collection_ids [Array<String>] a list of collection identifiers
|
31
|
-
# @param include_current_members [Boolean]
|
32
|
-
#
|
23
|
+
# @param include_current_members [Boolean] if true, include item's existing
|
24
|
+
# collections in check; else if false, check passed in collections only
|
25
|
+
# * use `false` when collection_ids includes proposed new collections and existing
|
26
|
+
# collections (@see Hyrax::Actors::CollectionsMembershipActor #valid_membership?)
|
27
|
+
# * use `true` when collection_ids includes proposed new collections only
|
28
|
+
# (@see Hyrax::Collections::CollectionMemberService #add_member)
|
33
29
|
#
|
34
30
|
# @return [nil, String] nil if no conflicts; an error message string if so
|
35
31
|
def check(collection_ids:, include_current_members: false)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
collections_to_check =
|
42
|
-
|
43
|
-
|
44
|
-
problematic_collections = collections_to_check.uniq(&:id)
|
45
|
-
.group_by(&:collection_type_gid)
|
46
|
-
.select { |_gid, list| list.count > 1 }
|
47
|
-
return if problematic_collections.blank?
|
32
|
+
return unless single_membership_collection_types_exist?
|
33
|
+
|
34
|
+
proposed_single_membership_collections = filter_to_single_membership_collections(collection_ids)
|
35
|
+
return if proposed_single_membership_collections.blank?
|
36
|
+
|
37
|
+
collections_to_check = collections_to_check(proposed_single_membership_collections,
|
38
|
+
include_current_members)
|
39
|
+
problematic_collections = check_collections(collections_to_check)
|
48
40
|
build_error_message(problematic_collections)
|
49
41
|
end
|
50
42
|
|
51
43
|
private
|
52
44
|
|
53
|
-
def
|
45
|
+
def single_membership_collection_types_exist?
|
46
|
+
single_membership_collection_types_gids.present?
|
47
|
+
end
|
48
|
+
|
49
|
+
def single_membership_collection_types_gids
|
50
|
+
@single_membership_collection_types_gids ||=
|
51
|
+
Hyrax::CollectionType.gids_that_do_not_allow_multiple_membership&.map(&:to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
def filter_to_single_membership_collections(collection_ids)
|
54
55
|
return [] if collection_ids.blank?
|
56
|
+
field_pairs = {
|
57
|
+
Hyrax.config.collection_type_index_field.to_sym => single_membership_collection_types_gids
|
58
|
+
}
|
59
|
+
Hyrax::SolrQueryService.new
|
60
|
+
.with_generic_type(generic_type: "Collection")
|
61
|
+
.with_ids(ids: Array[collection_ids])
|
62
|
+
.with_field_pairs(field_pairs: field_pairs, join_with: ' OR ')
|
63
|
+
.get_objects(use_valkyrie: true).to_a
|
64
|
+
end
|
55
65
|
|
56
|
-
|
66
|
+
def collections_to_check(proposed, include_current_members)
|
67
|
+
# ActorStack does a wholesale collection membership replacement, such that
|
68
|
+
# proposed collections include existing and new collections. Parameter
|
69
|
+
# `include_current_members` will be false when coming from the actor stack
|
70
|
+
# to prevent member items being passed in and then added here as well.
|
71
|
+
return proposed unless include_current_members
|
72
|
+
proposed | filter_to_single_membership_collections(item.member_of_collection_ids)
|
57
73
|
end
|
58
74
|
|
59
|
-
def
|
60
|
-
|
75
|
+
def check_collections(collections_to_check)
|
76
|
+
# uniq insures we include a collection only once when it is in the list multiple
|
77
|
+
# group_by groups collections of the same collection type together
|
78
|
+
# select keeps only collection type groups that have more than one collection
|
79
|
+
# of the single collection type
|
80
|
+
collections_to_check.uniq(&:id)
|
81
|
+
.group_by(&:collection_type_gid)
|
82
|
+
.select { |_gid, list| list.count > 1 }
|
61
83
|
end
|
62
84
|
|
63
85
|
def build_error_message(problematic_collections)
|
86
|
+
return if problematic_collections.blank?
|
64
87
|
error_message_clauses = problematic_collections.map do |gid, list|
|
65
88
|
I18n.t('hyrax.admin.collection_types.multiple_membership_checker.error_type_and_collections',
|
66
89
|
type: collection_type_title_from_gid(gid),
|
67
90
|
collections: collection_titles_from_list(list))
|
68
91
|
end
|
69
|
-
"#{I18n.t('hyrax.admin.collection_types.multiple_membership_checker.error_preamble')}
|
92
|
+
"#{I18n.t('hyrax.admin.collection_types.multiple_membership_checker.error_preamble')}" \
|
93
|
+
"#{error_message_clauses.join('; ')}"
|
70
94
|
end
|
71
95
|
|
72
96
|
def collection_type_title_from_gid(gid)
|
@@ -74,7 +98,7 @@ module Hyrax
|
|
74
98
|
end
|
75
99
|
|
76
100
|
def collection_titles_from_list(collection_list)
|
77
|
-
collection_list.
|
101
|
+
collection_list.map do |collection|
|
78
102
|
collection.title.first
|
79
103
|
end.to_sentence
|
80
104
|
end
|
@@ -143,7 +143,7 @@ module Hyrax
|
|
143
143
|
def groups_for(mode:)
|
144
144
|
Enumerator.new do |yielder|
|
145
145
|
acl.permissions.each do |permission|
|
146
|
-
next unless permission.mode == mode
|
146
|
+
next unless permission.mode.to_sym == mode
|
147
147
|
next unless permission.agent.starts_with?(Hyrax::Group.name_prefix)
|
148
148
|
yielder << permission.agent.gsub(Hyrax::Group.name_prefix, '')
|
149
149
|
end
|
@@ -154,7 +154,7 @@ module Hyrax
|
|
154
154
|
groups = groups.map(&:to_s)
|
155
155
|
|
156
156
|
acl.permissions.each do |permission|
|
157
|
-
next unless permission.mode == mode
|
157
|
+
next unless permission.mode.to_sym == mode
|
158
158
|
next unless permission.agent.starts_with?(Hyrax::Group.name_prefix)
|
159
159
|
|
160
160
|
group_name = permission.agent.gsub(Hyrax::Group.name_prefix, '')
|
@@ -175,7 +175,7 @@ module Hyrax
|
|
175
175
|
end
|
176
176
|
|
177
177
|
acl.permissions.each do |permission|
|
178
|
-
next unless permission.mode == mode
|
178
|
+
next unless permission.mode.to_sym == mode
|
179
179
|
next if permission.agent.starts_with?(Hyrax::Group.name_prefix)
|
180
180
|
next if users.include? permission.agent
|
181
181
|
|
@@ -189,7 +189,7 @@ module Hyrax
|
|
189
189
|
def users_for(mode:)
|
190
190
|
Enumerator.new do |yielder|
|
191
191
|
acl.permissions.each do |permission|
|
192
|
-
next unless permission.mode == mode
|
192
|
+
next unless permission.mode.to_sym == mode
|
193
193
|
next if permission.agent.starts_with?(Hyrax::Group.name_prefix)
|
194
194
|
yielder << permission.agent
|
195
195
|
end
|
@@ -18,7 +18,6 @@ module Hyrax
|
|
18
18
|
# Open the output file to write and yield the block to the
|
19
19
|
# file. It makes the directories in the path if necessary.
|
20
20
|
def self.output_file(directives, &blk)
|
21
|
-
# name = derivative_path_factory.derivative_path_for_reference(object, destination_name)
|
22
21
|
raise ArgumentError, "No :url was provided in the transcoding directives" unless directives.key?(:url)
|
23
22
|
uri = URI(directives.fetch(:url))
|
24
23
|
raise ArgumentError, "Must provide a file uri" unless uri.scheme == 'file'
|
@@ -27,7 +26,10 @@ module Hyrax
|
|
27
26
|
File.open(uri.path, 'wb', &blk)
|
28
27
|
end
|
29
28
|
|
29
|
+
##
|
30
|
+
# @deprecated
|
30
31
|
def self.derivative_path_factory
|
32
|
+
Deprecation.warn("Use 'Hyrax::DerivativePath' instead.")
|
31
33
|
DerivativePath
|
32
34
|
end
|
33
35
|
end
|
@@ -36,6 +36,13 @@ module Hyrax
|
|
36
36
|
self.resource = resource
|
37
37
|
end
|
38
38
|
|
39
|
+
##
|
40
|
+
# @param [#state] resource
|
41
|
+
# @return [Boolean]
|
42
|
+
def self.inactive?(resource:)
|
43
|
+
new(resource: resource).inactive?
|
44
|
+
end
|
45
|
+
|
39
46
|
##
|
40
47
|
# @return [Boolean]
|
41
48
|
# @raise [NoMethodError] if the resource doesn't have a state attribute
|
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# SearchService returns search results from the repository
|
4
3
|
module Hyrax
|
5
|
-
|
4
|
+
##
|
5
|
+
# Returns search results from the repository.
|
6
|
+
#
|
7
|
+
# @note Adapted from Blacklight 7
|
6
8
|
class SearchService
|
7
9
|
def initialize(config:, user_params: nil, search_builder_class: config.search_builder_class, **context)
|
8
10
|
@blacklight_config = config
|
@@ -1,37 +1,74 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Hyrax
|
3
|
+
##
|
4
|
+
# @deprecated
|
5
|
+
# This class is being replaced by Hyrax::SolrQueryService.
|
6
|
+
#
|
3
7
|
# Methods in this class are from/based on ActiveFedora::SolrQueryBuilder
|
8
|
+
#
|
9
|
+
# @see Hyrax::SolrQueryService
|
4
10
|
class SolrQueryBuilderService
|
5
11
|
class << self
|
6
12
|
# Construct a solr query for a list of ids
|
7
13
|
# This is used to get a solr response based on the list of ids in an object's RELS-EXT relationhsips
|
8
14
|
# If the id_array is empty, defaults to a query of "id:NEVER_USE_THIS_ID", which will return an empty solr response
|
9
15
|
# @param [Array] id_array the ids that you want included in the query
|
16
|
+
# @return [String] a solr query
|
17
|
+
# @example
|
18
|
+
# construct_query_for_ids(['a1', 'b2'])
|
19
|
+
# # => "{!terms f=id}a1,b2"
|
20
|
+
# @deprecated
|
10
21
|
def construct_query_for_ids(id_array)
|
22
|
+
Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
|
23
|
+
"Instead, use 'Hyrax::SolrQueryService.new.with_ids'.")
|
11
24
|
ids = id_array.reject(&:blank?)
|
12
25
|
return "id:NEVER_USE_THIS_ID" if ids.empty?
|
13
|
-
|
26
|
+
Hyrax::SolrQueryService.new.with_ids(ids: id_array).build
|
14
27
|
end
|
15
28
|
|
16
29
|
# Construct a solr query from a list of pairs (e.g. [field name, values])
|
17
|
-
# @param [
|
18
|
-
# @param [String] join_with
|
19
|
-
# @param [String] type
|
30
|
+
# @param [Hash] field_pairs a list of pairs of property name and values
|
31
|
+
# @param [String] join_with the value we're joining the clauses with (default: ' AND ')
|
32
|
+
# @param [String] type of query to run. Either 'raw' or 'field' (default: 'field')
|
20
33
|
# @return [String] a solr query
|
21
34
|
# @example
|
22
35
|
# construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
|
23
36
|
# # => "_query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\""
|
37
|
+
# @deprecated
|
24
38
|
def construct_query(field_pairs, join_with = default_join_with, type = 'field')
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
39
|
+
Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
|
40
|
+
"Instead, use 'Hyrax::SolrQueryService.new.with_field_pairs'.")
|
41
|
+
Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs,
|
42
|
+
join_with: join_with,
|
43
|
+
type: type).build
|
29
44
|
end
|
30
45
|
|
46
|
+
# @deprecated
|
31
47
|
def default_join_with
|
48
|
+
Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
|
49
|
+
"There will not be a replacement for this method. See Hyrax::SolrQueryService which is replacing this class.")
|
32
50
|
' AND '
|
33
51
|
end
|
34
52
|
|
53
|
+
# Construct a solr query from a list of pairs (e.g. [field name, values]) including the model (e.g. Collection, Monograph)
|
54
|
+
# @param [Class] model class
|
55
|
+
# @param [Hash] field_pairs a list of pairs of property name and values
|
56
|
+
# @param [String] join_with the value we're joining the clauses with (default: ' AND ')
|
57
|
+
# @param [String] type of query to run. Either 'raw' or 'field' (default: 'field')
|
58
|
+
# @return [String] a solr query
|
59
|
+
# @example
|
60
|
+
# construct_query(Collection, [['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
|
61
|
+
# # => "_query_:\"{!field f=has_model_ssim}Collection\" AND _query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\""
|
62
|
+
# @deprecated
|
63
|
+
def construct_query_for_model(model, field_pairs, join_with = default_join_with, type = 'field')
|
64
|
+
Deprecation.warn("'##{__method__}' will be removed in Hyrax 4.0. " \
|
65
|
+
"Instead, use 'Hyrax::SolrQueryService.new.with_model'.")
|
66
|
+
field_pairs["has_model_ssim"] = model.to_s
|
67
|
+
Hyrax::SolrQueryService.new.with_field_pairs(field_pairs: field_pairs,
|
68
|
+
join_with: join_with,
|
69
|
+
type: type).build
|
70
|
+
end
|
71
|
+
|
35
72
|
private
|
36
73
|
|
37
74
|
# @param [Array<Array>] pairs a list of (key, value) pairs. The value itself may
|
@@ -0,0 +1,224 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
##
|
4
|
+
# Supports building and executing a solr query.
|
5
|
+
#
|
6
|
+
# @note Methods in this class are providing functionality previously supported by
|
7
|
+
# ActiveFedora::SolrQueryBuilder.
|
8
|
+
class SolrQueryService < ::SearchBuilder # rubocop:disable Metrics/ClassLength
|
9
|
+
class_attribute :query_service
|
10
|
+
self.query_service = Hyrax.query_service
|
11
|
+
|
12
|
+
attr_reader :query, :solr_service
|
13
|
+
|
14
|
+
def initialize(query: [], solr_service: Hyrax::SolrService)
|
15
|
+
@query = query
|
16
|
+
@solr_service = solr_service
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# @api private
|
21
|
+
# @see Blacklight::Configuration#document_model
|
22
|
+
#
|
23
|
+
# @return [Class] the model class to use for solr documents
|
24
|
+
def self.document_model
|
25
|
+
CatalogController.blacklight_config.document_model
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# @return [Hash] the results returned from solr for the current query
|
30
|
+
def get
|
31
|
+
solr_service.get(build)
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# @return [Enumerable<SolrDocument>]
|
36
|
+
def solr_documents
|
37
|
+
get['response']['docs'].map { |doc| self.class.document_model.new(doc) }
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# @return [Array<String>] ids of documents matching the current query
|
42
|
+
def get_ids # rubocop:disable Naming/AccessorMethodName
|
43
|
+
results = get
|
44
|
+
results['response']['docs'].map { |doc| doc['id'] }
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# @return [Array<Valkyrie::Resource|ActiveFedora::Base>] objects matching the current query
|
49
|
+
def get_objects(use_valkyrie: Hyrax.config.use_valkyrie?)
|
50
|
+
ids = get_ids
|
51
|
+
return ids.map { |id| ActiveFedora::Base.find(id) } unless use_valkyrie
|
52
|
+
query_service.find_many_by_ids(ids: ids)
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# @return [Integer] the number of results that match the query in solr
|
57
|
+
def count
|
58
|
+
solr_service.count(build)
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# @return [String] the combined query that can be submitted to solr
|
63
|
+
def build
|
64
|
+
return 'id:NEVER_USE_THIS_ID' if @query.blank? # forces this method to always return a valid solr query
|
65
|
+
@query.join(' AND ')
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# @return [Hyrax::SolrQueryService] the existing service with the query reset to empty
|
70
|
+
def reset
|
71
|
+
@query = []
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# @param ids [Array] id_array the ids that you want included in the query
|
77
|
+
# @return [Hyrax::SolrQueryService] the existing service with id query appended
|
78
|
+
def with_ids(ids: [])
|
79
|
+
ids = ids.reject(&:blank?)
|
80
|
+
raise ArgumentError, "Expected there to be at least one non-blank id." if ids.blank?
|
81
|
+
id_query = construct_query_for_ids(ids)
|
82
|
+
@query += [id_query]
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# @param model [#to_s] a class from the model (e.g. Hyrax::Work, Hyrax::FileSet, etc.)
|
88
|
+
# @return [SolrQueryService] the existing service with model query appended
|
89
|
+
def with_model(model:)
|
90
|
+
model_query = construct_query_for_model(model)
|
91
|
+
@query += [model_query]
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# @param generic_type [String] (Default: Work)
|
97
|
+
# @return [SolrQueryService] the existing service with model query appended
|
98
|
+
def with_generic_type(generic_type: 'Work')
|
99
|
+
# TODO: Generic type was originally stored as `sim`. Since it is never multi-valued, it is moving to being stored
|
100
|
+
# as `si`. Until a migration is created to correct existing solr docs, this query searches in both fields.
|
101
|
+
field_pairs = { generic_type_si: generic_type, generic_type_sim: generic_type }
|
102
|
+
type_query = construct_query_for_pairs(field_pairs, ' OR ', 'field')
|
103
|
+
@query += [type_query]
|
104
|
+
self
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# @param field_pairs [Hash] a list of pairs of property name and values (e.g. { field1: values, field2: values })
|
109
|
+
# @param join_with [String] the connector used to join the field pairs (default: ' AND ')
|
110
|
+
# @param type [String] type of query to run. Either 'raw' or 'field' (default: 'field')
|
111
|
+
# @return [SolrQueryService] the existing service with field_pair query appended
|
112
|
+
def with_field_pairs(field_pairs: {}, join_with: default_join_with, type: 'field')
|
113
|
+
pairs_query = construct_query_for_pairs(field_pairs, join_with, type)
|
114
|
+
return self if pairs_query.blank?
|
115
|
+
@query += [pairs_query]
|
116
|
+
self
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# @param ability [???] the user's abilities
|
121
|
+
# @param action [Symbol] the action the user is taking (e.g. :index, :edit, :show, etc.) (default: :index)
|
122
|
+
# @return [SolrQueryService] the existing service with access filters query appended
|
123
|
+
def accessible_by(ability:, action: :index)
|
124
|
+
access_filters_query = construct_query_for_ability(ability, action)
|
125
|
+
@query += [access_filters_query] if access_filters_query.present?
|
126
|
+
self
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
# Construct a solr query for a list of ids
|
132
|
+
# @param [Array] ids to be included in the query
|
133
|
+
# @return [String] a solr query
|
134
|
+
# @example
|
135
|
+
# construct_query_for_ids(['id1', 'id2'])
|
136
|
+
# # => "{!terms f=id}id1,id2"
|
137
|
+
def construct_query_for_ids(ids)
|
138
|
+
"{!terms f=#{Hyrax.config.id_field}}#{ids.join(',')}"
|
139
|
+
end
|
140
|
+
|
141
|
+
# Construct a solr query from a list of pairs (e.g. { field1: values, field2: values })
|
142
|
+
# @param [Hash] field_pairs a list of pairs of property name and values
|
143
|
+
# @param [String] join_with the value we're joining the clauses with (default: ' AND ')
|
144
|
+
# @param [String] type of query to run. Either 'raw' or 'field' (default: 'field')
|
145
|
+
# @return [String] a solr query
|
146
|
+
# @example
|
147
|
+
# construct_query([['library_id_ssim', '123'], ['owner_ssim', 'Fred']])
|
148
|
+
# # => "_query_:\"{!field f=library_id_ssim}123\" AND _query_:\"{!field f=owner_ssim}Fred\""
|
149
|
+
def construct_query_for_pairs(field_pairs, join_with = default_join_with, type = 'field')
|
150
|
+
clauses = pairs_to_clauses(field_pairs, type)
|
151
|
+
return "" if clauses.count.zero?
|
152
|
+
return clauses.first if clauses.count == 1
|
153
|
+
"(#{clauses.join(join_with)})"
|
154
|
+
end
|
155
|
+
|
156
|
+
# Construct a solr query from the model (e.g. Collection, Monograph)
|
157
|
+
# @param [Class] model class
|
158
|
+
# @return [String] a solr query
|
159
|
+
# @example
|
160
|
+
# construct_query_for_model(Monograph)
|
161
|
+
# # => "_query_:\"{!field f=has_model_ssim}Monograph\""
|
162
|
+
def construct_query_for_model(model)
|
163
|
+
field_pairs = { "has_model_ssim" => model.to_s }
|
164
|
+
construct_query_for_pairs(field_pairs)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Construct a solr query based on a User's abilities and the action they taking
|
168
|
+
# @param ability [???] the user's abilities
|
169
|
+
# @param action [Symbol] the action the user is taking (e.g. :index, :edit, :show, etc.) (default: :index)
|
170
|
+
# @return [String] a solr query
|
171
|
+
# @example
|
172
|
+
# construct_query_for_ability(user, :edit)
|
173
|
+
# # => "(({!terms f=edit_access_group_ssim}public,user_group_A}) OR " \
|
174
|
+
# "edit_access_person_ssim:#{user@example.com})"
|
175
|
+
def construct_query_for_ability(ability, action)
|
176
|
+
permission_types = case action
|
177
|
+
when :index then [:discover, :read, :edit]
|
178
|
+
when :show, :read then [:read, :edit]
|
179
|
+
when :update, :edit, :create, :new, :destroy then [:edit]
|
180
|
+
end
|
181
|
+
filters = gated_discovery_filters(permission_types, ability).join(' OR ')
|
182
|
+
return "" if filters.blank?
|
183
|
+
"(#{filters})"
|
184
|
+
end
|
185
|
+
|
186
|
+
def default_join_with
|
187
|
+
' AND '
|
188
|
+
end
|
189
|
+
|
190
|
+
# @param [Array<Array>] pairs a list of (key, value) pairs. The value itself may
|
191
|
+
# @param [String] type The type of query to run. Either 'raw' or 'field'
|
192
|
+
# @return [Hash] a list of solr clauses
|
193
|
+
def pairs_to_clauses(pairs, type)
|
194
|
+
pairs.flat_map do |field, value|
|
195
|
+
condition_to_clauses(field, value, type)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
# @param [String] field
|
200
|
+
# @param [String, Array<String>] values
|
201
|
+
# @param [String] type The type of query to run. Either 'raw' or 'field'
|
202
|
+
# @return [Array<String>]
|
203
|
+
def condition_to_clauses(field, values, type)
|
204
|
+
values = Array(values)
|
205
|
+
values << nil if values.empty?
|
206
|
+
values.map do |value|
|
207
|
+
if value.present?
|
208
|
+
query_clause(type, field, value)
|
209
|
+
else
|
210
|
+
# Check that the field is not present. In SQL: "WHERE field IS NULL"
|
211
|
+
"-#{field}:[* TO *]"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# Create a raw query clause suitable for sending to solr as an fq element
|
217
|
+
# @param [String] type The type of query to run. Either 'raw' or 'field'
|
218
|
+
# @param [String] key
|
219
|
+
# @param [String] value
|
220
|
+
def query_clause(type, key, value)
|
221
|
+
"_query_:\"{!#{type} f=#{key}}#{value.gsub('"', '\"')}\""
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -37,7 +37,8 @@ module Hyrax
|
|
37
37
|
'Use `Hyrax.config.solr_select_path` instead'
|
38
38
|
end
|
39
39
|
|
40
|
-
delegate :add, :commit, :count, :delete, :get, :instance, :ping, :post,
|
40
|
+
delegate :add, :commit, :count, :delete, :get, :instance, :ping, :post,
|
41
|
+
:query, :delete_by_query, :search_by_id, :wipe!, to: :new
|
41
42
|
end
|
42
43
|
|
43
44
|
# Wraps rsolr get
|
@@ -100,6 +101,12 @@ module Hyrax
|
|
100
101
|
connection.delete_by_id(id, params: COMMIT_PARAMS)
|
101
102
|
end
|
102
103
|
|
104
|
+
# Deletes all solr documents
|
105
|
+
def wipe!
|
106
|
+
delete_by_query("*:*")
|
107
|
+
commit
|
108
|
+
end
|
109
|
+
|
103
110
|
# Wraps rsolr add
|
104
111
|
# @return [Hash] the hash straight form rsolr
|
105
112
|
def add(solr_doc, commit: true)
|
@@ -133,7 +140,7 @@ module Hyrax
|
|
133
140
|
# valkyrie indexers used here would, at minimum, need to provide a
|
134
141
|
# functioning `rsolr` connection.
|
135
142
|
def valkyrie_index
|
136
|
-
|
143
|
+
Hyrax.index_adapter
|
137
144
|
end
|
138
145
|
|
139
146
|
##
|
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# Gather information about the depositors who have contributed to the repository
|
3
2
|
module Hyrax
|
4
3
|
module Statistics
|
5
4
|
module Depositors
|
5
|
+
##
|
6
|
+
# Gather information about the depositors who have contributed to the repository
|
6
7
|
class Summary
|
7
8
|
include Blacklight::SearchHelper
|
8
9
|
|