geoblacklight_admin 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -9
  3. data/Rakefile +83 -47
  4. data/app/assets/javascripts/geoblacklight_admin/chosen.js +1 -0
  5. data/app/assets/stylesheets/geoblacklight_admin/_core.scss +24 -0
  6. data/app/assets/stylesheets/geoblacklight_admin/modules/_nav.scss +0 -5
  7. data/app/assets/stylesheets/geoblacklight_admin/modules/_tables.scss +1 -1
  8. data/app/controllers/admin/admin_controller.rb +16 -0
  9. data/app/controllers/admin/advanced_search_controller.rb +1 -1
  10. data/app/controllers/admin/assets_controller.rb +41 -5
  11. data/app/controllers/admin/bookmarks_controller.rb +14 -2
  12. data/app/controllers/admin/bulk_actions_controller.rb +31 -0
  13. data/app/controllers/admin/document_accesses_controller.rb +38 -0
  14. data/app/controllers/admin/document_assets_controller.rb +46 -9
  15. data/app/controllers/admin/document_distributions_controller.rb +172 -0
  16. data/app/controllers/admin/documents_controller.rb +41 -55
  17. data/app/controllers/admin/elements_controller.rb +22 -0
  18. data/app/controllers/admin/form_elements_controller.rb +31 -0
  19. data/app/controllers/admin/import_documents_controller.rb +11 -1
  20. data/app/controllers/admin/imports_controller.rb +32 -2
  21. data/app/controllers/admin/mappings_controller.rb +15 -0
  22. data/app/controllers/admin/notifications_controller.rb +27 -0
  23. data/app/controllers/admin/reference_types_controller.rb +106 -0
  24. data/app/controllers/admin/search_controller.rb +7 -0
  25. data/app/controllers/admin/users_controller.rb +10 -0
  26. data/app/helpers/asset_helper.rb +6 -0
  27. data/app/helpers/bulk_actions_helper.rb +9 -0
  28. data/app/helpers/document_helper.rb +36 -0
  29. data/app/helpers/geoblacklight_admin_helper.rb +88 -8
  30. data/app/helpers/mappings_helper.rb +26 -0
  31. data/app/indexers/document_indexer.rb +22 -2
  32. data/app/javascript/channels/consumer.js +6 -0
  33. data/app/javascript/channels/export_channel.js +30 -0
  34. data/app/javascript/channels/index.js +3 -0
  35. data/app/javascript/controllers/results_controller.js +14 -0
  36. data/app/javascript/index.js +8 -2
  37. data/app/jobs/export_job.rb +35 -8
  38. data/app/jobs/geoblacklight_admin/delete_thumbnail_job.rb +19 -0
  39. data/app/jobs/geoblacklight_admin/remove_parent_dct_references_uri_job.rb +16 -0
  40. data/app/jobs/geoblacklight_admin/set_parent_dct_references_uri_job.rb +17 -0
  41. data/app/jobs/geoblacklight_admin/store_image_job.rb +22 -0
  42. data/app/models/asset.rb +20 -0
  43. data/app/models/bulk_action.rb +2 -1
  44. data/app/models/document/geom_validator.rb +8 -0
  45. data/app/models/document/reference.rb +65 -65
  46. data/app/models/document.rb +128 -71
  47. data/app/models/document_distribution.rb +145 -0
  48. data/app/models/element.rb +2 -0
  49. data/app/models/geoblacklight_admin/schema.rb +10 -2
  50. data/app/models/import_document_state_machine.rb +1 -0
  51. data/app/models/reference_type.rb +40 -0
  52. data/app/models/user.rb +4 -2
  53. data/app/services/export_csv_document_distributions_service.rb +61 -0
  54. data/app/services/geoblacklight_admin/image_service/tms.rb +0 -4
  55. data/app/services/geoblacklight_admin/image_service.rb +1 -1
  56. data/app/services/geoblacklight_admin/item_viewer.rb +4 -4
  57. data/app/views/admin/bulk_actions/show.html.erb +1 -1
  58. data/app/views/admin/document_accesses/import.html.erb +6 -2
  59. data/app/views/admin/document_assets/_assets_table.html.erb +49 -0
  60. data/app/views/admin/document_assets/_form.html.erb +2 -3
  61. data/app/views/admin/document_assets/index.html.erb +1 -47
  62. data/app/views/admin/document_distributions/_document_distribution.html.erb +39 -0
  63. data/app/views/admin/document_distributions/_document_distribution.json.jbuilder +2 -0
  64. data/app/views/admin/document_distributions/_form.html.erb +34 -0
  65. data/app/views/admin/document_distributions/destroy_all.html.erb +82 -0
  66. data/app/views/admin/document_distributions/edit.html.erb +12 -0
  67. data/app/views/admin/document_distributions/import.html.erb +80 -0
  68. data/app/views/admin/document_distributions/index.html.erb +143 -0
  69. data/app/views/admin/document_distributions/index.json.jbuilder +1 -0
  70. data/app/views/admin/document_distributions/new.html.erb +11 -0
  71. data/app/views/admin/document_distributions/show.html.erb +10 -0
  72. data/app/views/admin/document_distributions/show.json.jbuilder +1 -0
  73. data/app/views/admin/documents/_document.html.erb +1 -3
  74. data/app/views/admin/documents/_form.html.erb +2 -4
  75. data/app/views/admin/documents/_form_control.html.erb +5 -2
  76. data/app/views/admin/documents/_form_nav.html.erb +14 -5
  77. data/app/views/admin/documents/_form_nav_kithe.html.erb +4 -1
  78. data/app/views/admin/documents/_json_aardvark.jbuilder +1 -1
  79. data/app/views/admin/documents/_json_gbl_v1.jbuilder +1 -1
  80. data/app/views/admin/documents/_result_selected_options.html.erb +5 -2
  81. data/app/views/admin/documents/admin.html.erb +5 -5
  82. data/app/views/admin/documents/features/_document_references.html.erb +23 -0
  83. data/app/views/admin/documents/features/_multiple_download_links.html.erb +29 -26
  84. data/app/views/admin/ids/fetch.json.jbuilder +0 -2
  85. data/app/views/admin/ids/index.json.jbuilder +0 -2
  86. data/app/views/admin/imports/_form.html.erb +1 -1
  87. data/app/views/admin/imports/show.html.erb +1 -1
  88. data/app/views/admin/layouts/application.html.erb +4 -2
  89. data/app/views/admin/reference_types/_form.html.erb +25 -0
  90. data/app/views/admin/reference_types/_reference_type.html.erb +52 -0
  91. data/app/views/admin/reference_types/_reference_type.json.jbuilder +2 -0
  92. data/app/views/admin/reference_types/edit.html.erb +12 -0
  93. data/app/views/admin/reference_types/index.html.erb +52 -0
  94. data/app/views/admin/reference_types/index.json.jbuilder +1 -0
  95. data/app/views/admin/reference_types/new.html.erb +11 -0
  96. data/app/views/admin/reference_types/show.html.erb +3 -0
  97. data/app/views/admin/reference_types/show.json.jbuilder +1 -0
  98. data/app/views/admin/shared/_footer.html.erb +5 -2
  99. data/app/views/admin/shared/_js_behaviors.html.erb +2 -3
  100. data/app/views/admin/shared/_navbar.html.erb +9 -2
  101. data/app/views/admin/users/index.html.erb +0 -1
  102. data/app/views/catalog/_show_gbl_admin.html.erb +1 -1
  103. data/config/initializers/defaults.yml +310 -0
  104. data/config/initializers/rails_config.rb +8 -0
  105. data/config/locales/documents.en.yml +14 -0
  106. data/config/routes.rb +30 -5
  107. data/db/import_references_schema_support.numbers +0 -0
  108. data/db/migrate/20230316183001_add_geoblacklight_admin_gem.rb +0 -12
  109. data/db/migrate/20241009200524_create_admin_reference_types.rb +13 -0
  110. data/db/migrate/20241010161420_create_document_references.rb +14 -0
  111. data/db/migrate/20241120238823_rename_references_to_distributions.rb +5 -0
  112. data/db/seeds.rb +5 -0
  113. data/db/seeds_elements.csv +1 -1
  114. data/db/seeds_elements.numbers +0 -0
  115. data/db/seeds_reference_types.csv +29 -0
  116. data/db/seeds_reference_types.numbers +0 -0
  117. data/db/structure.sql +1 -38
  118. data/lib/compose.yml +31 -0
  119. data/lib/generators/geoblacklight_admin/config_generator.rb +48 -12
  120. data/lib/generators/geoblacklight_admin/install_generator.rb +8 -0
  121. data/lib/generators/geoblacklight_admin/templates/config/database.yml +1 -1
  122. data/lib/generators/geoblacklight_admin/templates/config/initializers/devise.rb +0 -2
  123. data/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb +1 -0
  124. data/lib/generators/geoblacklight_admin/templates/demo-app/Dockerfile +31 -0
  125. data/lib/generators/geoblacklight_admin/templates/demo-app/compose.yml +42 -0
  126. data/lib/generators/geoblacklight_admin/templates/demo-app/start-server.sh +21 -0
  127. data/lib/geoblacklight_admin/engine.rb +4 -0
  128. data/lib/geoblacklight_admin/tasks/distributions.rake +69 -0
  129. data/lib/geoblacklight_admin/tasks/images.rake +1 -0
  130. data/lib/geoblacklight_admin/tasks/solr.rake +31 -0
  131. data/lib/geoblacklight_admin/version.rb +1 -1
  132. data/lib/geoblacklight_admin.rb +4 -0
  133. metadata +78 -41
  134. data/app/javascript/entrypoints/engine.js +0 -8
  135. data/config/locales/devise_invitable.en.yml +0 -31
  136. data/lib/generators/geoblacklight_admin/templates/devise/invitations/edit.html.erb +0 -15
  137. data/lib/generators/geoblacklight_admin/templates/devise/invitations/new.html.erb +0 -15
  138. data/lib/generators/geoblacklight_admin/templates/devise/mailer/invitation_instructions.html.erb +0 -11
  139. data/lib/generators/geoblacklight_admin/templates/devise/mailer/invitation_instructions.text.erb +0 -11
data/app/models/asset.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  class Asset < Kithe::Asset
2
+ belongs_to :parent, class_name: "Document", optional: true
3
+
2
4
  include AttrJson::Record::QueryScopes
3
5
  include Rails.application.routes.url_helpers
4
6
 
@@ -17,6 +19,8 @@ class Asset < Kithe::Asset
17
19
  "public" => :kithe_derivatives
18
20
  }.freeze
19
21
 
22
+ scope :to_aardvark_references, -> { where(parent_id: pluck(:parent_id)).map(&:to_aardvark_reference) }
23
+
20
24
  def full_file_url
21
25
  if Rails.env.development?
22
26
  "http://localhost:3000" + file.url
@@ -45,6 +49,22 @@ class Asset < Kithe::Asset
45
49
  def reindex_parent
46
50
  parent.save if parent.present?
47
51
  end
52
+
53
+ def to_aardvark_reference
54
+ hash = {}
55
+ if dct_references_uri_key.present?
56
+ reference_type = ReferenceType.find_by_name(dct_references_uri_key)
57
+ hash[reference_type.reference_uri.to_s] = if reference_type.reference_uri.to_s == "http://schema.org/downloadUrl"
58
+ {
59
+ "url" => full_file_url,
60
+ "label" => label.present? ? label : file.metadata["filename"]
61
+ }
62
+ else
63
+ full_file_url
64
+ end
65
+ end
66
+ hash
67
+ end
48
68
  end
49
69
 
50
70
  # Allow DocumentAsset to be used as a synonym for Asset
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "uri"
4
4
  require "cgi"
5
+ require "statesman"
5
6
 
6
7
  # BulkAction
7
8
  class BulkAction < ApplicationRecord
@@ -19,7 +20,7 @@ class BulkAction < ApplicationRecord
19
20
  validates :scope, :field_name, :field_value, presence: true
20
21
 
21
22
  # States
22
- include Statesman::Adapters::ActiveRecordQueries[
23
+ include ::Statesman::Adapters::ActiveRecordQueries[
23
24
  transition_class: BulkActionTransition,
24
25
  initial_state: :created
25
26
  ]
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rgeo"
4
+ require "rgeo/wkrep/wkt_parser"
4
5
 
5
6
  # GEOM Validation
6
7
  #
@@ -65,6 +66,13 @@ class Document
65
66
  "Invalid polygon: all points are coplanar input, Solr will not index")
66
67
  end
67
68
 
69
+ # Guard against coplanar points
70
+ if geom == "POLYGON((-180.0 90.0, 180.0 90.0, 180.0 -90.0, -180.0 -90.0, -180.0 90.0))"
71
+ valid_geom = false
72
+ record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[:geometry],
73
+ "Invalid polygon: all points are coplanar input, Solr will not index")
74
+ end
75
+
68
76
  valid_geom
69
77
  end
70
78
 
@@ -7,17 +7,37 @@ class Document
7
7
  # Via GBL Wiki
8
8
  # https://github.com/geoblacklight/geoblacklight/wiki/External-references
9
9
  REFERENCE_VALUES = {
10
- wcs: {
11
- label: "Web Coverage Service (WCS)",
12
- uri: "http://www.opengis.net/def/serviceType/ogc/wcs"
10
+ arcgis_dynamic_map_layer: {
11
+ label: "ArcGIS DynamicMapLayer",
12
+ uri: "urn:x-esri:serviceType:ArcGIS#DynamicMapLayer"
13
13
  },
14
- wms: {
15
- label: "Web Mapping Service (WMS)",
16
- uri: "http://www.opengis.net/def/serviceType/ogc/wms"
14
+ arcgis_feature_layer: {
15
+ label: "ArcGIS FeatureLayer",
16
+ uri: "urn:x-esri:serviceType:ArcGIS#FeatureLayer"
17
17
  },
18
- wfs: {
19
- label: "Web Feature Service (WFS)",
20
- uri: "http://www.opengis.net/def/serviceType/ogc/wfs"
18
+ arcgis_image_map_layer: {
19
+ label: "ArcGIS ImageMapLayer",
20
+ uri: "urn:x-esri:serviceType:ArcGIS#ImageMapLayer"
21
+ },
22
+ arcgis_tiled_map_layer: {
23
+ label: "ArcGIS TiledMapLayer",
24
+ uri: "urn:x-esri:serviceType:ArcGIS#TiledMapLayer"
25
+ },
26
+ cog: {
27
+ label: "COG",
28
+ uri: "https://github.com/cogeotiff/cog-spec"
29
+ },
30
+ documentation_download: {
31
+ label: "Data dictionary / documentation download",
32
+ uri: "http://lccn.loc.gov/sh85035852"
33
+ },
34
+ documentation_external: {
35
+ label: "Full layer description",
36
+ uri: "http://schema.org/url"
37
+ },
38
+ download: {
39
+ label: "Direct download file",
40
+ uri: "http://schema.org/downloadUrl"
21
41
  },
22
42
  iiif_image: {
23
43
  label: "IIIF Image API",
@@ -31,81 +51,37 @@ class Document
31
51
  label: "Image file",
32
52
  uri: "http://schema.org/image"
33
53
  },
34
- download: {
35
- label: "Direct download file",
36
- uri: "http://schema.org/downloadUrl"
37
- },
38
- thumbnail: {
39
- label: "Thumbnail file",
40
- uri: "http://schema.org/thumbnailUrl"
41
- },
42
- documentation_download: {
43
- label: "Data dictionary / documentation download",
44
- uri: "http://lccn.loc.gov/sh85035852"
45
- },
46
- documentation_external: {
47
- label: "Full layer description",
48
- uri: "http://schema.org/url"
49
- },
50
- metadata_iso: {
51
- label: "Metadata in ISO 19139",
52
- uri: "http://www.isotc211.org/schemas/2005/gmd/"
53
- },
54
54
  metadata_fgdc: {
55
55
  label: "Metadata in FGDC",
56
56
  uri: "http://www.opengis.net/cat/csw/csdgm"
57
57
  },
58
- metadata_mods: {
59
- label: "Metadata in MODS",
60
- uri: "http://www.loc.gov/mods/v3"
61
- },
62
58
  metadata_html: {
63
59
  label: "Metadata in HTML",
64
60
  uri: "http://www.w3.org/1999/xhtml"
65
61
  },
66
- arcgis_feature_layer: {
67
- label: "ArcGIS FeatureLayer",
68
- uri: "urn:x-esri:serviceType:ArcGIS#FeatureLayer"
69
- },
70
- arcgis_tiled_map_layer: {
71
- label: "ArcGIS TiledMapLayer",
72
- uri: "urn:x-esri:serviceType:ArcGIS#TiledMapLayer"
73
- },
74
- arcgis_dynamic_map_layer: {
75
- label: "ArcGIS DynamicMapLayer",
76
- uri: "urn:x-esri:serviceType:ArcGIS#DynamicMapLayer"
77
- },
78
- arcgis_image_map_layer: {
79
- label: "ArcGIS ImageMapLayer",
80
- uri: "urn:x-esri:serviceType:ArcGIS#ImageMapLayer"
81
- },
82
- harvard_download: {
83
- label: "Harvard Download",
84
- uri: "http://schema.org/DownloadAction"
62
+ metadata_iso: {
63
+ label: "Metadata in ISO 19139",
64
+ uri: "http://www.isotc211.org/schemas/2005/gmd/"
85
65
  },
86
- open_index_map: {
87
- label: "OpenIndexMap",
88
- uri: "https://openindexmaps.org"
66
+ metadata_mods: {
67
+ label: "Metadata in MODS",
68
+ uri: "http://www.loc.gov/mods/v3"
89
69
  },
90
70
  oembed: {
91
71
  label: "oEmbed",
92
72
  uri: "https://oembed.com"
93
73
  },
94
- cog: {
95
- label: "COG",
96
- uri: "https://github.com/cogeotiff/cog-spec"
74
+ open_index_map: {
75
+ label: "OpenIndexMap",
76
+ uri: "https://openindexmaps.org"
97
77
  },
98
78
  pmtiles: {
99
79
  label: "PMTiles",
100
80
  uri: "https://github.com/protomaps/PMTiles"
101
81
  },
102
- xyz_tiles: {
103
- label: "XYZ Tiles",
104
- uri: "https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames"
105
- },
106
- wmts: {
107
- label: "WMTS",
108
- uri: "http://www.opengis.net/def/serviceType/ogc/wmts"
82
+ thumbnail: {
83
+ label: "Thumbnail file",
84
+ uri: "http://schema.org/thumbnailUrl"
109
85
  },
110
86
  tile_json: {
111
87
  label: "TileJSON",
@@ -114,6 +90,26 @@ class Document
114
90
  tile_map_service: {
115
91
  label: "Tile Map Service",
116
92
  uri: "https://wiki.osgeo.org/wiki/Tile_Map_Service_Specification"
93
+ },
94
+ wcs: {
95
+ label: "Web Coverage Service (WCS)",
96
+ uri: "http://www.opengis.net/def/serviceType/ogc/wcs"
97
+ },
98
+ wfs: {
99
+ label: "Web Feature Service (WFS)",
100
+ uri: "http://www.opengis.net/def/serviceType/ogc/wfs"
101
+ },
102
+ wmts: {
103
+ label: "WMTS",
104
+ uri: "http://www.opengis.net/def/serviceType/ogc/wmts"
105
+ },
106
+ wms: {
107
+ label: "Web Mapping Service (WMS)",
108
+ uri: "http://www.opengis.net/def/serviceType/ogc/wms"
109
+ },
110
+ xyz_tiles: {
111
+ label: "XYZ Tiles",
112
+ uri: "https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames"
117
113
  }
118
114
  }.freeze
119
115
 
@@ -127,5 +123,9 @@ class Document
127
123
 
128
124
  attr_json :category, :string
129
125
  attr_json :value, :string
126
+
127
+ def self.reference_values
128
+ REFERENCE_VALUES
129
+ end
130
130
  end
131
131
  end
@@ -9,7 +9,7 @@ class Document < Kithe::Work
9
9
  delegate :viewer_endpoint, to: :item_viewer
10
10
 
11
11
  def item_viewer
12
- GeoblacklightAdmin::ItemViewer.new(references)
12
+ GeoblacklightAdmin::ItemViewer.new(distributions)
13
13
  end
14
14
 
15
15
  attr_accessor :skip_callbacks
@@ -34,18 +34,20 @@ class Document < Kithe::Work
34
34
  has_many :document_downloads, primary_key: "friendlier_id", foreign_key: "friendlier_id", autosave: false, dependent: :destroy,
35
35
  inverse_of: :document
36
36
 
37
+ # - DocumentDistributions
38
+ has_many :document_distributions, primary_key: "friendlier_id", foreign_key: "friendlier_id", autosave: false, dependent: :destroy,
39
+ inverse_of: :document
40
+
37
41
  # DocumentAssets - Thumbnails, Attachments, etc
38
42
  # @TODO: Redundant? Kithe also includes a members association
39
43
  def document_assets
40
44
  scope = Kithe::Asset
41
- scope = scope.where(parent_id: id)
42
-
43
- # scope = scope.page(params[:page]).per(20).order(created_at: :desc)
45
+ scope = scope.where(parent_id: id).order(position: :asc)
44
46
  scope.includes(:parent)
45
47
  end
46
48
 
47
- def downloadable_assets
48
- document_assets.select { |a| a.dct_references_uri_key == "download" }
49
+ def distributable_assets
50
+ document_assets.select { |a| a.dct_references_uri_key.present? }
49
51
  end
50
52
 
51
53
  include Statesman::Adapters::ActiveRecordQueries[
@@ -87,7 +89,7 @@ class Document < Kithe::Work
87
89
 
88
90
  # Downloadable Resouce
89
91
  def a_downloadable_resource?
90
- references_json.include?("downloadUrl")
92
+ distributions_json.include?("downloadUrl")
91
93
  end
92
94
 
93
95
  validates_with Document::DateValidator
@@ -96,55 +98,109 @@ class Document < Kithe::Work
96
98
  validates_with Document::GeomValidator
97
99
 
98
100
  # Definte our AttrJSON attributes
99
- Element.all.each do |attribute|
100
- next if attribute.solr_field == "dct_references_s"
101
+ if ActiveRecord::Base.connection.table_exists?("elements")
102
+ Element.all.each do |attribute|
103
+ next if attribute.solr_field == "dct_references_s"
101
104
 
102
- if attribute.repeatable?
103
- attr_json attribute.solr_field.to_sym, attribute.field_type.to_sym, array: true, default: -> { [] }
104
- else
105
- attr_json attribute.solr_field.to_sym, attribute.field_type.to_sym, default: ""
105
+ if attribute.repeatable?
106
+ attr_json attribute.solr_field.to_sym, attribute.field_type.to_sym, array: true, default: -> { [] }
107
+ else
108
+ attr_json attribute.solr_field.to_sym, attribute.field_type.to_sym, default: ""
109
+ end
106
110
  end
107
111
  end
108
112
 
109
113
  attr_json :dct_references_s, Document::Reference.to_type, array: true, default: -> { [] }
110
114
 
111
- # Index Transformations - *_json functions
112
- def references
113
- references = ActiveSupport::HashWithIndifferentAccess.new
115
+ # Distributions
116
+ # - BEFORE DocumentDistributions
117
+ # - Use dct_references_s
118
+ # - Use multiple downloads
119
+ # - Use distributable assets
120
+ # - AFTER DocumentDistributions
121
+ # - Use document_distributions
122
+ # - Use distributable assets
123
+ # @TODO: Remove BEFORE path once we've migrated to DocumentDistributions
124
+ def distributions
125
+ distributions = ActiveSupport::HashWithIndifferentAccess.new
126
+
127
+ # AFTER - Add DocumentDistributions to distributions
128
+ if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "true"
129
+ distributions = document_distributions.to_aardvark_distributions
130
+ end
114
131
 
115
- # Prep value arrays
132
+ # BEFORE - Prep value arrays
133
+ # @TODO: Remove this once we've migrated to DocumentDistributions
116
134
  send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
117
- references[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = []
135
+ if ref.category.present?
136
+ distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = []
137
+ end
118
138
  end
119
139
 
120
- # Seed value arrays
140
+ # BEFORE - Seed value arrays
141
+ # @TODO: Remove this once we've migrated to DocumentDistributions
121
142
  send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
122
- # @TODO: Need to support multiple entries per key here
123
- references[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] << ref.value
143
+ if ref.category.present?
144
+ distributions[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] << ref.value
145
+ end
124
146
  end
147
+ logger.debug("\n\nDocument#distributions > seeded: #{distributions}")
125
148
 
126
- logger.debug("\n\nDocument#references > seeded: #{references}")
127
-
128
- # Apply Downloads
129
- references = apply_downloads(references)
149
+ # BEFORE - Apply Multiple Downloads
150
+ # @TODO: Remove this once we've migrated to DocumentDistributions
151
+ if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "false"
152
+ distributions = apply_downloads(distributions)
153
+ logger.debug("Document#distributions > downloads: #{distributions}")
154
+ end
130
155
 
131
- logger.debug("Document#references > downloads: #{references}\n\n")
156
+ # BEFORE & AFTER - Apply Distributable Assets
157
+ distributions = apply_assets(distributions)
158
+ logger.debug("Document#distributions > assets: #{distributions}")
132
159
 
133
160
  # Need to flatten the arrays here to avoid the following potential error:
134
161
  # - ArgumentError: Please use symbols for polymorphic route arguments.
135
162
  # - Via: app/helpers/geoblacklight_helper.rb:224:in `render_references_url'
136
- references.each do |key, value|
163
+ distributions.each do |key, value|
137
164
  next if key == "http://schema.org/downloadUrl"
138
165
  if value.is_a?(Array) && value.length == 1
139
- references[key] = value.first
166
+ distributions[key] = value.first
140
167
  end
141
168
  end
142
169
 
143
- references
170
+ distributions
171
+ end
172
+
173
+ # Distributions JSON
174
+ # - Indexes to Solr as dct_distributions_s
175
+ def distributions_json
176
+ if ENV["GBL_ADMIN_REFERENCES_MIGRATED"] == "true"
177
+ logger.debug("Document#distributions_json > using document_distributions")
178
+ distributions = document_distributions.to_aardvark_distributions
179
+ distributions = apply_assets(distributions)
180
+ distributions.to_json
181
+ else
182
+ logger.debug("Document#distributions > #{distributions.inspect}")
183
+ logger.debug("Document#distributions_json > using distributions")
184
+ logger.warn("Deprecation warning: AttrJSON-based dct_references_s will not be supported soon.")
185
+ self.distributions.to_json
186
+ end
144
187
  end
145
188
 
146
- def references_json
147
- references.to_json
189
+ def distributions_csv
190
+ # Initialize CSV
191
+ # - [document_id, category, value, label]
192
+ csv = []
193
+
194
+ distributions.each do |key, value|
195
+ if key == "http://schema.org/downloadUrl"
196
+ value.each do |download|
197
+ csv << [friendlier_id, ReferenceType.find_by(reference_uri: key).name, download["url"], download["label"]]
198
+ end
199
+ else
200
+ csv << [friendlier_id, ReferenceType.find_by(reference_uri: key)&.name, value, nil]
201
+ end
202
+ end
203
+ csv
148
204
  end
149
205
 
150
206
  def asset_label(asset)
@@ -155,14 +211,33 @@ class Document < Kithe::Work
155
211
  end
156
212
  end
157
213
 
158
- # Apply Downloads
214
+ def apply_assets(distributions)
215
+ # Distributable Document Assets
216
+ # - Via DocumentAssets (Assets)
217
+ # - With Downloadable URI
218
+ if distributable_assets.present?
219
+ distributable_assets.each do |asset|
220
+ if asset.dct_references_uri_key == "download"
221
+ distributions["http://schema.org/downloadUrl"] ||= []
222
+ distributions["http://schema.org/downloadUrl"] << asset.to_aardvark_reference["http://schema.org/downloadUrl"]
223
+ else
224
+ distributions.merge!(asset.to_aardvark_reference)
225
+ end
226
+ end
227
+ end
228
+
229
+ distributions
230
+ end
231
+
232
+ # BEFORE - Apply Downloads
233
+ # @TODO: Remove this once we've migrated to DocumentDistributions
159
234
  # 1. Native Aardvark Downloads
160
235
  # 2. Multiple Document Download Links
161
236
  # 3. Downloadable Document Assets
162
- def apply_downloads(references)
237
+ def apply_downloads(distributions)
163
238
  multiple_downloads = []
164
239
 
165
- dct_downloads = references["http://schema.org/downloadUrl"]
240
+ dct_downloads = distributions["http://schema.org/downloadUrl"]
166
241
 
167
242
  logger.debug("Document#dct_downloads > init: #{dct_downloads}\n\n")
168
243
 
@@ -180,35 +255,21 @@ class Document < Kithe::Work
180
255
  # Multiple Document Download Links
181
256
  # - Via DocumentDownloads
182
257
  if document_downloads.present?
183
- multiple_downloads << multiple_downloads_array
258
+ multiple_downloads_array.each do |download|
259
+ multiple_downloads << download
260
+ end
184
261
  end
185
262
 
186
263
  logger.debug("Document#dct_downloads > document_downloads: #{multiple_downloads.inspect}\n\n")
187
264
 
188
- # Downloadable Document Assets
189
- # - Via DocumentAssets (Assets)
190
- # - With Downloadable URI
191
- if downloadable_assets.present?
192
- downloadable_assets.each do |asset|
193
- logger.debug("\n\n Document#dct_downloads > dupe?: #{multiple_downloads.detect { |d| d[:url].include?(asset.file.url) }}\n\n")
194
-
195
- if multiple_downloads.detect { |d| d[:url].include?(asset.file.url) }
196
- logger.debug("\n\n Detected duplicate download URL: #{asset.file.url}\n\n")
197
- index = multiple_downloads.index { |d| d[:url].include?(asset.file.url) }
198
- multiple_downloads[index] = {label: asset_label(asset), url: asset.file.url}
199
- else
200
- logger.debug("\n\n No duplicate found - Adding downloadable asset: #{asset.file.url}\n\n")
201
- multiple_downloads << {label: asset_label(asset), url: asset.file.url}
202
- end
203
- end
204
- end
265
+ multiple_downloads = multiple_downloads.uniq { |d| [d[:label], d[:url]] } unless multiple_downloads.empty?
205
266
 
206
- logger.debug("Document#dct_downloads > downloadable_assets: #{multiple_downloads.inspect}\n\n")
207
-
208
- references[:"http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty?
209
- references
267
+ distributions[:"http://schema.org/downloadUrl"] = multiple_downloads.flatten unless multiple_downloads.empty?
268
+ distributions
210
269
  end
211
270
 
271
+ # BEFORE - Multiple Downloads Array
272
+ # @TODO: Remove this once we've migrated to DocumentDistributions
212
273
  def multiple_downloads_array
213
274
  document_downloads.collect { |d| {label: d.label, url: d.value} }
214
275
  end
@@ -230,14 +291,9 @@ class Document < Kithe::Work
230
291
  #
231
292
  def download_text(format)
232
293
  download_format = proper_case_format(format)
233
- prefix = "Original "
234
- begin
235
- format = download_format
236
- rescue
237
- # Need to rescue if format doesn't exist
238
- end
239
- value = prefix + format.to_s
240
- value.html_safe
294
+ download_format.to_s.html_safe
295
+ rescue
296
+ format.to_s.html_safe
241
297
  end
242
298
 
243
299
  ##
@@ -273,7 +329,7 @@ class Document < Kithe::Work
273
329
  end
274
330
 
275
331
  def direct_download
276
- references.download.to_hash if references.download.present?
332
+ distributions.download.to_hash if distributions.download.present?
277
333
  end
278
334
 
279
335
  def display_note
@@ -281,11 +337,11 @@ class Document < Kithe::Work
281
337
  end
282
338
 
283
339
  def hgl_download
284
- references.hgl.to_hash if references.hgl.present?
340
+ distributions.hgl.to_hash if distributions.hgl.present?
285
341
  end
286
342
 
287
343
  def oembed
288
- references.oembed.endpoint if references.oembed.present?
344
+ distributions.oembed.endpoint if distributions.oembed.present?
289
345
  end
290
346
 
291
347
  def same_institution?
@@ -294,15 +350,15 @@ class Document < Kithe::Work
294
350
  end
295
351
 
296
352
  def iiif_download
297
- references.iiif.to_hash if references.iiif.present?
353
+ distributions.iiif.to_hash if distributions.iiif.present?
298
354
  end
299
355
 
300
356
  def data_dictionary_download
301
- references.data_dictionary.to_hash if references.data_dictionary.present?
357
+ distributions.data_dictionary.to_hash if distributions.data_dictionary.present?
302
358
  end
303
359
 
304
360
  def external_url
305
- references.url&.endpoint
361
+ distributions.url&.endpoint
306
362
  end
307
363
 
308
364
  def itemtype
@@ -332,7 +388,7 @@ class Document < Kithe::Work
332
388
  # :type => a string which if its a Geoblacklight::Constants::URI key
333
389
  # will return a coresponding Geoblacklight::Reference
334
390
  def checked_endpoint(type)
335
- type = references.send(type)
391
+ type = distributions.send(type)
336
392
  type.endpoint if type.present?
337
393
  end
338
394
 
@@ -397,6 +453,7 @@ class Document < Kithe::Work
397
453
  elsif value[:destination] == "b1g_publication_state_s"
398
454
  send(:current_state)
399
455
  else
456
+ next if send(value[:destination]).blank?
400
457
  send(value[:destination])
401
458
  end
402
459
  end