blacklight_allmaps 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4303c5d59179db61e16867a11549e7c4ef6f642b6732619c3a78967b0d089655
4
- data.tar.gz: 5d294dc06d1b846b631d43c7af5ff30b93a79a27fff0b20ce8281d13a3a1d032
3
+ metadata.gz: 68d2d44ebaeae3f57846f37606e6a576e06a50d452e629cc715fbaf68a307f59
4
+ data.tar.gz: 61c1cb052866a522abe1e743da1e15d483e86ee96550f7081bacdb491f69c83c
5
5
  SHA512:
6
- metadata.gz: e3afe56c0665e20d189436302c1a37609a73d4b07d46c390a70e392f1bc7f2625e509f2e53ce35b338a272163836e343226778a3ffc71d973d3e4f67b8449ed7
7
- data.tar.gz: ed11adf2ed33e2abf96747df563e91a85b2dacacb62fe71aa90e504d52eebfbb52c51b7abf189e4c2c52793fd3b581d3e503b2dba1094ff6f16f60bfe967aac7
6
+ metadata.gz: 62f5d6a8a91d32fe95b3f205e31eb1a9d92776239aae871d8984feb65660b8bd4e6ba9133fde12bd49a1cee547eae5bef894e013aa54672853cef08be3a9278b
7
+ data.tar.gz: 49efe24708e9ca9e04308a591e82e7e48baf85b4c4ef5fc4b2e650ce53024e5ad86ff8510a90fb1dd86d7a0a2602b9f68a82cec9854afb0470d6b7b0dc86be51
data/README.md CHANGED
@@ -29,14 +29,26 @@ Run the install generator:
29
29
 
30
30
  ```bash
31
31
  # For Blacklight...
32
- LIGHT=blacklight bundle exec rake blacklight:allmaps:install
32
+ LIGHT=blacklight bundle exec rails generate blacklight:allmaps:install
33
33
 
34
34
  # For GeoBlacklight
35
- LIGHT=geoblacklight bundle exec rake blacklight:allmaps:install
35
+ LIGHT=geoblacklight bundle exec rails generate blacklight:allmaps:install
36
36
  ```
37
37
 
38
38
  ## Rake Tasks
39
39
 
40
+ ### Seed Fixtures
41
+
42
+ To populate Solr with some example data, you can run these tasks
43
+
44
+ ```bash
45
+ # For Blacklight...
46
+ LIGHT=blacklight rake blacklight_allmaps:index:bl_fixtures
47
+
48
+ # For GeoBlacklight...
49
+ LIGHT=geoblacklight rake rake blacklight_allmaps:index:gbl_fixtures
50
+ ```
51
+
40
52
  ### Harvest Allmaps IIIF Annotation Data
41
53
 
42
54
  We harvest and store Allmaps IIIF Annotation data locally — see the Blacklight::Allmaps::Sidecar section below.
@@ -44,6 +56,7 @@ We harvest and store Allmaps IIIF Annotation data locally — see the Blacklight
44
56
  The rake task here kicks off a background harvest process that walks through your Solr index documents (using CursorMark) and checks each document for `georeferenceable?` - the presence of a IIIF Manifest. If the document is indeed georeferenceable? (true) we ping the Allmaps API to determine if the map/item has already been georeferenced in Allmaps.
45
57
 
46
58
  ```bash
59
+ # For Blacklight or GeoBlacklight
47
60
  rake blacklight_allmaps:sidecars:harvest:allmaps
48
61
  ```
49
62
 
@@ -53,13 +66,11 @@ We expose the georeferenced items in the Blacklight user interface via a Georefe
53
66
 
54
67
  ![Screen shot](doc/georeferenced_facet.png)
55
68
 
56
- #### Blacklight
57
-
58
- @TODO
59
-
60
- #### GeoBlacklight
61
-
62
69
  ```bash
70
+ # For Blacklight...
71
+ LIGHT=blacklight rake blacklight_allmaps:index:bl_georeferenced_facet
72
+
73
+ # For GeoBlacklight...
63
74
  LIGHT=geoblacklight rake blacklight_allmaps:index:gbl_georeferenced_facet
64
75
  ```
65
76
 
@@ -67,22 +78,26 @@ LIGHT=geoblacklight rake blacklight_allmaps:index:gbl_georeferenced_facet
67
78
 
68
79
  Blacklight::Allmaps adopts the SolrDocumentSidecar "sidecar" pattern from [Spotlight](https://github.com/projectblacklight/spotlight), adding an ActiveRecord object to the database for each SolrDocument object in the index.
69
80
 
70
- The Blacklight::Allmaps::Sidecar object contains:
81
+ We use this `document.sidecar_allmaps` object to hold the results of the Allmaps Annotation harvest task.
71
82
 
72
- * id: primary key
73
- * solr_document_id: solr document primary key
74
- * document_type SolrDocument
75
- * manifest_id: IIIF Manifest ID
76
- * annotated: boolean (true|false)
77
- * allmaps_id: Allmaps ID
78
- * iiif_manifest: Copy of the IIIF Manifest
79
- * allmaps_annotation: Copy of the Allmaps IIIF Annotation
80
- * solr_version: solr document version number
81
- * created_at: created at
82
- * updated_at: updated at
83
+ The Blacklight::Allmaps::Sidecar object contains:
84
+ | Field | Value |
85
+ | --- | --- |
86
+ | id | primary key |
87
+ | solr_document_id | solr document primary key |
88
+ | document_type | SolrDocument |
89
+ | manifest_id | IIIF Manifest ID |
90
+ | annotated | boolean (true\|false) |
91
+ | allmaps_id | Allmaps ID |
92
+ | iiif_manifest | Copy of the IIIF Manifest |
93
+ | allmaps_annotation | Copy of the Allmaps IIIF Annotation |
94
+ | solr_version | solr document version number |
95
+ | created_at | timestamp |
96
+ | updated_at | timestamp |
83
97
 
84
98
  ```ruby
85
- document.sidecar =>
99
+ document = SolrDocument.find('harvard-g4124-m2-1855-m3')
100
+ document.sidecar_allmaps =>
86
101
  #<Blacklight::Allmaps::Sidecar:0x0000000141991a50
87
102
  id: 1,
88
103
  solr_document_id: "harvard-g4124-m2-1855-m3",
@@ -103,7 +118,5 @@ document.sidecar =>
103
118
 
104
119
  For Developer documentation see [doc/developer.md](./doc/development.md)
105
120
 
106
- Additional Contribution directions to come...
107
-
108
121
  ## License
109
122
  The gem is available as open source under the terms of the [Apache 2.0 License](https://opensource.org/license/apache-2-0).
data/Rakefile CHANGED
@@ -40,7 +40,8 @@ namespace :blacklight_allmaps do
40
40
  end
41
41
 
42
42
  # Harvest Allmaps data
43
- system "rake blacklight_allmaps:sidecars:harvest:allmaps"
43
+ # rake db:fixtures:load (if necessary)
44
+ # system "rake blacklight_allmaps:sidecars:harvest:allmaps"
44
45
  end
45
46
  end
46
47
 
@@ -16,34 +16,36 @@
16
16
  </ul>
17
17
 
18
18
  <div class="tab-content mt-3">
19
- <div class="tab-pane fade show active" id="item-viewer-tab" role="tabpanel" aria-labelledby="item-viewer-tab">
20
- <% if show_help_text?('viewer_protocol', document.viewer_protocol) %>
21
- <%= render_help_text_entry('viewer_protocol', document.viewer_protocol) %>
22
- <% end %>
19
+ <div class="tab-pane active" id="item-viewer-tab" role="tabpanel" aria-labelledby="item-viewer-tab">
20
+ <div id="viewer-wrapper">
21
+ <% if show_help_text?('viewer_protocol', document.viewer_protocol) %>
22
+ <%= render_help_text_entry('viewer_protocol', document.viewer_protocol) %>
23
+ <% end %>
23
24
 
24
- <% if document.item_viewer.index_map %>
25
- <div class="index-map-legend">
26
- <div class="index-map-legend-info">
27
- <span class="index-map-legend-default"></span>
28
- <p><span class="sr-only">Green tile indicates </span>Map held by collection</p>
25
+ <% if document.item_viewer.index_map %>
26
+ <div class="index-map-legend">
27
+ <div class="index-map-legend-info">
28
+ <span class="index-map-legend-default"></span>
29
+ <p><span class="sr-only">Green tile indicates </span>Map held by collection</p>
30
+ </div>
31
+ <div class="index-map-legend-info">
32
+ <span class="index-map-legend-unavailable"></span>
33
+ <p><span class="sr-only">Yellow tile indicates </span>Map not held by collection</p>
34
+ </div>
35
+ <div class="index-map-legend-info">
36
+ <span class="index-map-legend-selected"></span>
37
+ <p><span class="sr-only">Blue tile indicates </span>Selected map tile</p>
38
+ </div>
29
39
  </div>
30
- <div class="index-map-legend-info">
31
- <span class="index-map-legend-unavailable"></span>
32
- <p><span class="sr-only">Yellow tile indicates </span>Map not held by collection</p>
33
- </div>
34
- <div class="index-map-legend-info">
35
- <span class="index-map-legend-selected"></span>
36
- <p><span class="sr-only">Blue tile indicates </span>Selected map tile</p>
37
- </div>
38
- </div>
39
- <% end %>
40
+ <% end %>
40
41
 
41
- <%= content_tag :div, id: 'map', aria: { label: t('geoblacklight.map.label') }, data: { map: 'item', protocol: document.viewer_protocol.camelize, url: document.viewer_endpoint, 'layer-id' => document.wxs_identifier, 'map-geom' => document.geometry.geojson, 'catalog-path'=> search_catalog_path, available: document_available?, inspect: show_attribute_table?, basemap: geoblacklight_basemap, leaflet_options: leaflet_options } do %>
42
- <% end %>
42
+ <%= content_tag :div, id: 'map', aria: { label: t('geoblacklight.map.label') }, data: { map: 'item', protocol: document.viewer_protocol.camelize, url: document.viewer_endpoint, 'layer-id' => document.wxs_identifier, 'map-geom' => document.geometry.geojson, 'catalog-path'=> search_catalog_path, available: document_available?, inspect: show_attribute_table?, basemap: geoblacklight_basemap, leaflet_options: leaflet_options } do %>
43
+ <% end %>
44
+ </div>
43
45
  </div>
44
46
 
45
47
  <% if document.sidecar_allmaps.georeferenced? %>
46
- <div class="tab-pane fade" id="georeferenced-tab" role="tabpanel" aria-labelledby="georeferenced-tab">
48
+ <div class="tab-pane" id="georeferenced-tab" role="tabpanel" aria-labelledby="georeferenced-tab">
47
49
  <%= render partial: 'allmaps/show/geoblacklight', locals: { document: document } %>
48
50
  </div>
49
51
  <% end %>
@@ -1,4 +1,4 @@
1
- class CreateSolrDocumentSidecars < ActiveRecord::Migration[7.0]
1
+ class CreateSolrDocumentSidecarAllmaps < ActiveRecord::Migration[7.0]
2
2
  def change
3
3
  create_table :blacklight_allmaps_sidecars do |t|
4
4
  t.string :solr_document_id, index: true
@@ -6,15 +6,14 @@ namespace :blacklight_allmaps do
6
6
  namespace :index do
7
7
  desc "Index - add Allmaps fixture data to Blacklight solr"
8
8
  task :bl_fixtures do
9
- # @TODO: JSON works when pasted into Solr, but fails here?
10
- docs = Dir["spec/fixtures/solr_documents/bl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
9
+ docs = Dir["#{Blacklight::Allmaps.root}/spec/fixtures/solr_documents/blacklight/bl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
11
10
  Blacklight.default_index.connection.add docs
12
11
  Blacklight.default_index.connection.commit
13
12
  end
14
13
 
15
14
  desc "Index - add Allmaps fixture data to GeoBlacklight solr"
16
15
  task :gbl_fixtures do
17
- docs = Dir["spec/fixtures/solr_documents/gbl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
16
+ docs = Dir["#{Blacklight::Allmaps.root}/spec/fixtures/solr_documents/geoblacklight/gbl_*.json"].map { |f| JSON.parse File.read(f) }.flatten
18
17
  Blacklight.default_index.connection.add docs
19
18
  Blacklight.default_index.connection.commit
20
19
  end
@@ -44,7 +43,7 @@ namespace :blacklight_allmaps do
44
43
  response["response"]["docs"].each do |doc|
45
44
  # 2. Determine which documents have georeferenced data
46
45
  solr_document = SolrDocument.find(doc["id"])
47
- if solr_document.sidecar.present? && solr_document.sidecar.annotated?
46
+ if solr_document.sidecar_allmaps.present? && solr_document.sidecar_allmaps.annotated?
48
47
 
49
48
  # 3. Clean JSON for re-indexing
50
49
  keys_for_deletion = %w[
@@ -73,5 +72,55 @@ namespace :blacklight_allmaps do
73
72
  end
74
73
  Blacklight.default_index.connection.commit
75
74
  end
75
+
76
+ desc "Index - add Allmaps facet data to Blacklight solr"
77
+ task bl_georeferenced_facet: [:environment] do
78
+ # Steps
79
+ # 1. Use cursor to paginate all documents in Solr
80
+ # 2. Determine which documents have georeferenced data
81
+ # 3. Clean JSON for re-indexing
82
+ # 4. Add bl_georeferenced_bsi values
83
+ # 5. Re-index the georeferenced documents
84
+
85
+ # 1. Get all the documents from Solr
86
+ cursor_mark = "*"
87
+ loop do
88
+ response = Blacklight.default_index.connection.get(
89
+ "select", params: {
90
+ q: "*:*", # all docs
91
+ fl: "*", # all fields
92
+ cursorMark: cursor_mark, # use the cursor mark to handle paging
93
+ rows: 1000,
94
+ sort: "id asc" # must sort by id to use the cursor mark
95
+ }
96
+ )
97
+
98
+ response["response"]["docs"].each do |doc|
99
+ # 2. Determine which documents have georeferenced data
100
+ solr_document = SolrDocument.find(doc["id"])
101
+ if solr_document.sidecar_allmaps.present? && solr_document.sidecar_allmaps.annotated?
102
+
103
+ # 3. Clean JSON for re-indexing
104
+ keys_for_deletion = %w[
105
+ _version_
106
+ timestamp
107
+ ]
108
+
109
+ cleaned_doc = doc.except!(*keys_for_deletion)
110
+
111
+ # 4. Add gbl_georeferenced_b value
112
+ # @TODO: add allmaps_id?
113
+ cleaned_doc["bl_georeferenced_bsi"] = true
114
+
115
+ # 5. Re-index the georeferenced documents
116
+ Blacklight.default_index.connection.add cleaned_doc
117
+ end
118
+ end
119
+
120
+ break if response["nextCursorMark"] == cursor_mark # this means the result set is finished
121
+ cursor_mark = response["nextCursorMark"]
122
+ end
123
+ Blacklight.default_index.connection.commit
124
+ end
76
125
  end
77
126
  end
@@ -1,5 +1,14 @@
1
1
  module Blacklight
2
2
  module Allmaps
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
+
5
+ def self.version
6
+ @version ||= VERSION
7
+ end
8
+
9
+ # returns the full path the the plugin installation
10
+ def self.root
11
+ @root ||= File.expand_path(File.dirname(__FILE__, 4))
12
+ end
4
13
  end
5
14
  end
@@ -3,5 +3,6 @@ require "blacklight"
3
3
  module Blacklight
4
4
  module Allmaps
5
5
  require "blacklight/allmaps/engine"
6
+ require "blacklight/allmaps/version"
6
7
  end
7
8
  end
@@ -16,13 +16,21 @@ module Blacklight
16
16
  copy_file "manifest.js", "app/assets/config/manifest.js", force: true
17
17
  end
18
18
 
19
+ def add_assets_initialier
20
+ append_to_file "config/initializers/assets.rb" do
21
+ "
22
+ # Blacklight Allmaps
23
+ Rails.application.config.assets.precompile += %w( blacklight/allmaps/allmaps-logo.svg )"
24
+ end
25
+ end
26
+
19
27
  def copy_rake_tasks
20
28
  append_to_file "Rakefile", "require 'blacklight/allmaps/rake_task'\n"
21
29
  end
22
30
 
23
31
  def prioritize_blacklight_allmaps_views
24
- inject_into_file "config/application.rb", "\nrequire \"blacklight/allmaps/engine\"\n", after: "require \"action_cable/engine\""
25
- inject_into_file "config/application.rb", "\nconfig.railties_order = [Blacklight::Allmaps::Engine, :main_app, :all]\n", after: "class Application < Rails::Application\n"
32
+ inject_into_file "config/application.rb", "\nrequire \"blacklight/allmaps/engine\"\n", before: "# Require the gems listed in Gemfile"
33
+ inject_into_file "config/application.rb", "\n config.railties_order = [Blacklight::Allmaps::Engine, :main_app, :all]\n", after: "class Application < Rails::Application\n"
26
34
  end
27
35
 
28
36
  def add_importmap_pins
@@ -49,6 +57,13 @@ module Blacklight
49
57
  "\n include Blacklight::Allmaps::SolrDocument"
50
58
  end
51
59
  end
60
+
61
+ def add_bl_georeferenced_facet
62
+ return unless ENV["LIGHT"] == "blacklight"
63
+ inject_into_file "app/controllers/catalog_controller.rb", after: "config.add_facet_field 'subject_era_ssim', label: 'Era'" do
64
+ "\n config.add_facet_field 'bl_georeferenced_bsi', label: 'Georeferenced'"
65
+ end
66
+ end
52
67
  end
53
68
  end
54
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_allmaps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Larson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-27 00:00:00.000000000 Z
11
+ date: 2024-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blacklight
@@ -190,7 +190,7 @@ files:
190
190
  - app/views/catalog/_show_sidebar_blacklight.html.erb
191
191
  - app/views/catalog/_show_sidebar_geoblacklight.html.erb
192
192
  - config/routes.rb
193
- - db/migrate/20240307155110_create_solr_document_sidecars.rb
193
+ - db/migrate/20240307155110_create_solr_document_sidecar_allmaps.rb
194
194
  - lib/blacklight/allmaps.rb
195
195
  - lib/blacklight/allmaps/engine.rb
196
196
  - lib/blacklight/allmaps/rake_task.rb