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.
- checksums.yaml +4 -4
- data/README.md +18 -9
- data/Rakefile +83 -47
- data/app/assets/javascripts/geoblacklight_admin/chosen.js +1 -0
- data/app/assets/stylesheets/geoblacklight_admin/_core.scss +24 -0
- data/app/assets/stylesheets/geoblacklight_admin/modules/_nav.scss +0 -5
- data/app/assets/stylesheets/geoblacklight_admin/modules/_tables.scss +1 -1
- data/app/controllers/admin/admin_controller.rb +16 -0
- data/app/controllers/admin/advanced_search_controller.rb +1 -1
- data/app/controllers/admin/assets_controller.rb +41 -5
- data/app/controllers/admin/bookmarks_controller.rb +14 -2
- data/app/controllers/admin/bulk_actions_controller.rb +31 -0
- data/app/controllers/admin/document_accesses_controller.rb +38 -0
- data/app/controllers/admin/document_assets_controller.rb +46 -9
- data/app/controllers/admin/document_distributions_controller.rb +172 -0
- data/app/controllers/admin/documents_controller.rb +41 -55
- data/app/controllers/admin/elements_controller.rb +22 -0
- data/app/controllers/admin/form_elements_controller.rb +31 -0
- data/app/controllers/admin/import_documents_controller.rb +11 -1
- data/app/controllers/admin/imports_controller.rb +32 -2
- data/app/controllers/admin/mappings_controller.rb +15 -0
- data/app/controllers/admin/notifications_controller.rb +27 -0
- data/app/controllers/admin/reference_types_controller.rb +106 -0
- data/app/controllers/admin/search_controller.rb +7 -0
- data/app/controllers/admin/users_controller.rb +10 -0
- data/app/helpers/asset_helper.rb +6 -0
- data/app/helpers/bulk_actions_helper.rb +9 -0
- data/app/helpers/document_helper.rb +36 -0
- data/app/helpers/geoblacklight_admin_helper.rb +88 -8
- data/app/helpers/mappings_helper.rb +26 -0
- data/app/indexers/document_indexer.rb +22 -2
- data/app/javascript/channels/consumer.js +6 -0
- data/app/javascript/channels/export_channel.js +30 -0
- data/app/javascript/channels/index.js +3 -0
- data/app/javascript/controllers/results_controller.js +14 -0
- data/app/javascript/index.js +8 -2
- data/app/jobs/export_job.rb +35 -8
- data/app/jobs/geoblacklight_admin/delete_thumbnail_job.rb +19 -0
- data/app/jobs/geoblacklight_admin/remove_parent_dct_references_uri_job.rb +16 -0
- data/app/jobs/geoblacklight_admin/set_parent_dct_references_uri_job.rb +17 -0
- data/app/jobs/geoblacklight_admin/store_image_job.rb +22 -0
- data/app/models/asset.rb +20 -0
- data/app/models/bulk_action.rb +2 -1
- data/app/models/document/geom_validator.rb +8 -0
- data/app/models/document/reference.rb +65 -65
- data/app/models/document.rb +128 -71
- data/app/models/document_distribution.rb +145 -0
- data/app/models/element.rb +2 -0
- data/app/models/geoblacklight_admin/schema.rb +10 -2
- data/app/models/import_document_state_machine.rb +1 -0
- data/app/models/reference_type.rb +40 -0
- data/app/models/user.rb +4 -2
- data/app/services/export_csv_document_distributions_service.rb +61 -0
- data/app/services/geoblacklight_admin/image_service/tms.rb +0 -4
- data/app/services/geoblacklight_admin/image_service.rb +1 -1
- data/app/services/geoblacklight_admin/item_viewer.rb +4 -4
- data/app/views/admin/bulk_actions/show.html.erb +1 -1
- data/app/views/admin/document_accesses/import.html.erb +6 -2
- data/app/views/admin/document_assets/_assets_table.html.erb +49 -0
- data/app/views/admin/document_assets/_form.html.erb +2 -3
- data/app/views/admin/document_assets/index.html.erb +1 -47
- data/app/views/admin/document_distributions/_document_distribution.html.erb +39 -0
- data/app/views/admin/document_distributions/_document_distribution.json.jbuilder +2 -0
- data/app/views/admin/document_distributions/_form.html.erb +34 -0
- data/app/views/admin/document_distributions/destroy_all.html.erb +82 -0
- data/app/views/admin/document_distributions/edit.html.erb +12 -0
- data/app/views/admin/document_distributions/import.html.erb +80 -0
- data/app/views/admin/document_distributions/index.html.erb +143 -0
- data/app/views/admin/document_distributions/index.json.jbuilder +1 -0
- data/app/views/admin/document_distributions/new.html.erb +11 -0
- data/app/views/admin/document_distributions/show.html.erb +10 -0
- data/app/views/admin/document_distributions/show.json.jbuilder +1 -0
- data/app/views/admin/documents/_document.html.erb +1 -3
- data/app/views/admin/documents/_form.html.erb +2 -4
- data/app/views/admin/documents/_form_control.html.erb +5 -2
- data/app/views/admin/documents/_form_nav.html.erb +14 -5
- data/app/views/admin/documents/_form_nav_kithe.html.erb +4 -1
- data/app/views/admin/documents/_json_aardvark.jbuilder +1 -1
- data/app/views/admin/documents/_json_gbl_v1.jbuilder +1 -1
- data/app/views/admin/documents/_result_selected_options.html.erb +5 -2
- data/app/views/admin/documents/admin.html.erb +5 -5
- data/app/views/admin/documents/features/_document_references.html.erb +23 -0
- data/app/views/admin/documents/features/_multiple_download_links.html.erb +29 -26
- data/app/views/admin/ids/fetch.json.jbuilder +0 -2
- data/app/views/admin/ids/index.json.jbuilder +0 -2
- data/app/views/admin/imports/_form.html.erb +1 -1
- data/app/views/admin/imports/show.html.erb +1 -1
- data/app/views/admin/layouts/application.html.erb +4 -2
- data/app/views/admin/reference_types/_form.html.erb +25 -0
- data/app/views/admin/reference_types/_reference_type.html.erb +52 -0
- data/app/views/admin/reference_types/_reference_type.json.jbuilder +2 -0
- data/app/views/admin/reference_types/edit.html.erb +12 -0
- data/app/views/admin/reference_types/index.html.erb +52 -0
- data/app/views/admin/reference_types/index.json.jbuilder +1 -0
- data/app/views/admin/reference_types/new.html.erb +11 -0
- data/app/views/admin/reference_types/show.html.erb +3 -0
- data/app/views/admin/reference_types/show.json.jbuilder +1 -0
- data/app/views/admin/shared/_footer.html.erb +5 -2
- data/app/views/admin/shared/_js_behaviors.html.erb +2 -3
- data/app/views/admin/shared/_navbar.html.erb +9 -2
- data/app/views/admin/users/index.html.erb +0 -1
- data/app/views/catalog/_show_gbl_admin.html.erb +1 -1
- data/config/initializers/defaults.yml +310 -0
- data/config/initializers/rails_config.rb +8 -0
- data/config/locales/documents.en.yml +14 -0
- data/config/routes.rb +30 -5
- data/db/import_references_schema_support.numbers +0 -0
- data/db/migrate/20230316183001_add_geoblacklight_admin_gem.rb +0 -12
- data/db/migrate/20241009200524_create_admin_reference_types.rb +13 -0
- data/db/migrate/20241010161420_create_document_references.rb +14 -0
- data/db/migrate/20241120238823_rename_references_to_distributions.rb +5 -0
- data/db/seeds.rb +5 -0
- data/db/seeds_elements.csv +1 -1
- data/db/seeds_elements.numbers +0 -0
- data/db/seeds_reference_types.csv +29 -0
- data/db/seeds_reference_types.numbers +0 -0
- data/db/structure.sql +1 -38
- data/lib/compose.yml +31 -0
- data/lib/generators/geoblacklight_admin/config_generator.rb +48 -12
- data/lib/generators/geoblacklight_admin/install_generator.rb +8 -0
- data/lib/generators/geoblacklight_admin/templates/config/database.yml +1 -1
- data/lib/generators/geoblacklight_admin/templates/config/initializers/devise.rb +0 -2
- data/lib/generators/geoblacklight_admin/templates/config/initializers/mime_types.rb +1 -0
- data/lib/generators/geoblacklight_admin/templates/demo-app/Dockerfile +31 -0
- data/lib/generators/geoblacklight_admin/templates/demo-app/compose.yml +42 -0
- data/lib/generators/geoblacklight_admin/templates/demo-app/start-server.sh +21 -0
- data/lib/geoblacklight_admin/engine.rb +4 -0
- data/lib/geoblacklight_admin/tasks/distributions.rake +69 -0
- data/lib/geoblacklight_admin/tasks/images.rake +1 -0
- data/lib/geoblacklight_admin/tasks/solr.rake +31 -0
- data/lib/geoblacklight_admin/version.rb +1 -1
- data/lib/geoblacklight_admin.rb +4 -0
- metadata +78 -41
- data/app/javascript/entrypoints/engine.js +0 -8
- data/config/locales/devise_invitable.en.yml +0 -31
- data/lib/generators/geoblacklight_admin/templates/devise/invitations/edit.html.erb +0 -15
- data/lib/generators/geoblacklight_admin/templates/devise/invitations/new.html.erb +0 -15
- data/lib/generators/geoblacklight_admin/templates/devise/mailer/invitation_instructions.html.erb +0 -11
- 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
|
data/app/models/bulk_action.rb
CHANGED
|
@@ -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
|
-
|
|
11
|
-
label: "
|
|
12
|
-
uri: "
|
|
10
|
+
arcgis_dynamic_map_layer: {
|
|
11
|
+
label: "ArcGIS DynamicMapLayer",
|
|
12
|
+
uri: "urn:x-esri:serviceType:ArcGIS#DynamicMapLayer"
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
label: "
|
|
16
|
-
uri: "
|
|
14
|
+
arcgis_feature_layer: {
|
|
15
|
+
label: "ArcGIS FeatureLayer",
|
|
16
|
+
uri: "urn:x-esri:serviceType:ArcGIS#FeatureLayer"
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
label: "
|
|
20
|
-
uri: "
|
|
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
|
-
|
|
67
|
-
label: "
|
|
68
|
-
uri: "
|
|
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
|
-
|
|
87
|
-
label: "
|
|
88
|
-
uri: "
|
|
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
|
-
|
|
95
|
-
label: "
|
|
96
|
-
uri: "https://
|
|
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
|
-
|
|
103
|
-
label: "
|
|
104
|
-
uri: "
|
|
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
|
data/app/models/document.rb
CHANGED
|
@@ -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(
|
|
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
|
|
48
|
-
document_assets.select { |a| a.dct_references_uri_key
|
|
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
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
+
distributions[key] = value.first
|
|
140
167
|
end
|
|
141
168
|
end
|
|
142
169
|
|
|
143
|
-
|
|
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
|
|
147
|
-
|
|
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
|
-
|
|
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(
|
|
237
|
+
def apply_downloads(distributions)
|
|
163
238
|
multiple_downloads = []
|
|
164
239
|
|
|
165
|
-
dct_downloads =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
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
|
-
|
|
340
|
+
distributions.hgl.to_hash if distributions.hgl.present?
|
|
285
341
|
end
|
|
286
342
|
|
|
287
343
|
def oembed
|
|
288
|
-
|
|
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
|
-
|
|
353
|
+
distributions.iiif.to_hash if distributions.iiif.present?
|
|
298
354
|
end
|
|
299
355
|
|
|
300
356
|
def data_dictionary_download
|
|
301
|
-
|
|
357
|
+
distributions.data_dictionary.to_hash if distributions.data_dictionary.present?
|
|
302
358
|
end
|
|
303
359
|
|
|
304
360
|
def external_url
|
|
305
|
-
|
|
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 =
|
|
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
|