Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ewlarson committed Dec 8, 2023
2 parents 70bb9a9 + 90cc6be commit 1da9fbd
Show file tree
Hide file tree
Showing 39 changed files with 956 additions and 46 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ bundle exec rails server
### Lint App
```bash
standardrb .
standardrb --fix
```

### Test App
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/admin/ids_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class IdsController < Admin::AdminController
# Publication State
config.add_facet_field Settings.FIELDS.B1G_PUBLICATION_STATE, show: false

# Import ID
config.add_facet_field Settings.FIELDS.B1G_IMPORT_ID, label: "Import ID", show: false

# Resouce Class
config.add_facet_field Settings.FIELDS.RESOURCE_CLASS, show: false

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def index
# GET /imports/1
# GET /imports/1.json
def show
@pagy_failed, @import_failed_documents = pagy(@import.import_documents.not_in_state(:success), items: 100)
@pagy_success, @import_success_documents = pagy(@import.import_documents.in_state(:success), items: 100)
@pagy_failed, @import_failed_documents = pagy(@import.import_documents.not_in_state(:success), items: 50)
@pagy_success, @import_success_documents = pagy(@import.import_documents.in_state(:success), items: 50)
end

# GET /imports/new
Expand Down
30 changes: 30 additions & 0 deletions app/helpers/geoblacklight_admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,34 @@ def diff_class(char)
""
end
end

def link_to_admin_import(import)
path = admin_documents_path(
{
f: {b1g_geom_import_id_ssi: [import]}
}
)

link_to import.name, path
end

def link_to_gbl_import(label, import, state = false)
path = if state
blacklight_path(
{
f: {b1g_geom_import_id_ssi: [import]},
publication_state: state
}
)
else
blacklight_path(
{
f: {b1g_geom_import_id_ssi: [import]},
publication_state: "*"
}
)
end

link_to(label, path)
end
end
11 changes: 11 additions & 0 deletions app/jobs/bulk_action_collect_documents.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

# BulkActionCollectDocuments class
class BulkActionCollectDocuments < ApplicationJob
queue_as :priority

def perform(bulk_action_id)
bulk_action = BulkAction.find(bulk_action_id)
bulk_action.collect_documents
end
end
12 changes: 12 additions & 0 deletions app/jobs/geoblacklight_admin/store_image_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module GeoblacklightAdmin
class StoreImageJob < ApplicationJob
queue_as :default

def perform(solr_document_id)
document = Document.find_by_friendlier_id(solr_document_id)
GeoblacklightAdmin::ImageService.new(document).store
end
end
end
13 changes: 13 additions & 0 deletions app/models/asset.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Asset < Kithe::Asset
include AttrJson::Record::QueryScopes

set_shrine_uploader(AssetUploader)

# AttrJSON
attr_json :thumbnail, :boolean, default: "false"
attr_json :derivative_storage_type, :string, default: "public"

DERIVATIVE_STORAGE_TYPE_LOCATIONS = {
"public" => :kithe_derivatives
}.freeze
end
13 changes: 8 additions & 5 deletions app/models/bulk_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# BulkAction
class BulkAction < ApplicationRecord
# Callbacks
after_create_commit :collect_documents
after_create do
BulkActionCollectDocuments.perform_later(id)
end

# Associations
has_many :documents, class_name: "BulkActionDocument", autosave: false, dependent: :destroy
Expand Down Expand Up @@ -38,18 +40,17 @@ def run!
end

def check_run_state
return if state_machine.current_state == "complete"
nil if state_machine.current_state == "complete"

state_machine.transition_to!(:complete) if documents.in_state(:queued).blank?
# @TODO / background job for collecting documents
# state_machine.transition_to!(:complete) if documents.in_state(:queued).blank?
end

def revert!
# Queue Revert Job
BulkActionRevertJob.perform_later(self)
end

private

def collect_documents
cgi = CGI.unescape(scope)
uri = URI.parse(cgi)
Expand All @@ -60,6 +61,8 @@ def collect_documents
end
end

private

def fetch_documents(uri)
qargs = Rack::Utils.parse_nested_query(uri.query)
fetch_documents = Document.where(friendlier_id: qargs["ids"])
Expand Down
21 changes: 21 additions & 0 deletions app/models/bulk_actions/change_publication_state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module BulkActions
# Subclass for ChangePublicationState
class ChangePublicationState < BulkAction
# Add specific methods and validations for ChangePublicationState here
end

# Subclass for PublishDocument
class PublishDocument < BulkAction
# Add specific methods and validations for PublishDocument here
end

# Subclass for UnpublishDocument
class UnpublishDocument < BulkAction
# Add specific methods and validations for UnpublishDocument here
end

# Subclass for DraftDocument
class DraftDocument < BulkAction
# Add specific methods and validations for DraftDocument here
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module GeoblacklightAdmin
module PublicationStateSearchBehavior
extend ActiveSupport::Concern

included do
self.default_processor_chain += [:publication_state_records]
end

##
# Show/Hide records by publication state in search
# Defaults to "published" items only
# publication_state: ['published', 'unpublished', 'draft']
# @param [Blacklight::Solr::Request]
# @return [Blacklight::Solr::Request]
def publication_state_records(solr_params)
solr_params[:fq] ||= []
solr_params[:fq] << if blacklight_params["publication_state"]
"b1g_publication_state_s:#{blacklight_params["publication_state"]}"
else
"b1g_publication_state_s:published"
end
end
end
end
116 changes: 114 additions & 2 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ class Document < Kithe::Work
include AttrJson::Record::QueryScopes
include ActiveModel::Validations

delegate :viewer_protocol, to: :item_viewer
delegate :viewer_endpoint, to: :item_viewer

def item_viewer
GeoblacklightAdmin::ItemViewer.new(references)
end

attr_accessor :skip_callbacks

has_paper_trail ignore: [:publication_state]
Expand Down Expand Up @@ -50,6 +57,7 @@ def a_downloadable_resource?
references_json.include?("downloadUrl")
end

validates_with Document::DateValidator
validates_with Document::DateRangeValidator
validates_with Document::BboxValidator
validates_with Document::GeomValidator
Expand All @@ -68,12 +76,15 @@ def a_downloadable_resource?
attr_json :dct_references_s, Document::Reference.to_type, array: true, default: -> { [] }

# Index Transformations - *_json functions
def references_json
def references
references = ActiveSupport::HashWithIndifferentAccess.new
send(GeoblacklightAdmin::Schema.instance.solr_fields[:reference]).each do |ref|
references[Document::Reference::REFERENCE_VALUES[ref.category.to_sym][:uri]] = ref.value
end
references = apply_downloads(references)
apply_downloads(references)
end

def references_json
references.to_json
end

Expand Down Expand Up @@ -121,8 +132,109 @@ def download_text(format)
value = prefix + format.to_s
value.html_safe
end

##
# GBL SolrDocument convience methods
#
def available?
public? || same_institution?
end

def public?
rights_field_data.present? && rights_field_data.casecmp("public").zero?
end

def local_restricted?
local? && restricted?
end

def local?
local = send(Settings.FIELDS.PROVIDER) || ""
local.casecmp(Settings.INSTITUTION_LOCAL_NAME)&.zero?
end

def restricted?
rights_field_data.blank? || rights_field_data.casecmp("restricted").zero?
end

def rights_field_data
send(Settings.FIELDS.ACCESS_RIGHTS) || ""
end

def downloadable?
(direct_download || download_types.present? || iiif_download) && available?
end

def direct_download
references.download.to_hash if references.download.present?
end

def display_note
send(Settings.FIELDS.DISPLAY_NOTE) || ""
end

def hgl_download
references.hgl.to_hash if references.hgl.present?
end

def oembed
references.oembed.endpoint if references.oembed.present?
end

def same_institution?
institution = send(Settings.FIELDS.PROVIDER) || ""
institution.casecmp(Settings.INSTITUTION.downcase).zero?
end

def iiif_download
references.iiif.to_hash if references.iiif.present?
end

def data_dictionary_download
references.data_dictionary.to_hash if references.data_dictionary.present?
end

def external_url
references.url&.endpoint
end

def itemtype
"http://schema.org/Dataset"
end

def geom_field
send(Settings.FIELDS.GEOMETRY) || ""
end

def geometry
# @TODO
# @geometry ||= Geoblacklight::Geometry.new(geom_field)
end

def wxs_identifier
send(Settings.FIELDS.WXS_IDENTIFIER) || ""
end

def file_format
send(Settings.FIELDS.FORMAT) || ""
end

##
# Provides a convenience method to access a SolrDocument's References
# endpoint url without having to check and see if it is available
# :type => a string which if its a Geoblacklight::Constants::URI key
# will return a coresponding Geoblacklight::Reference
def checked_endpoint(type)
type = references.send(type)
type.endpoint if type.present?
end

### End / From GBL

def thumbnail
members.find { |m| m.respond_to?(:thumbnail) }
end

def access_json
access = {}
access_urls.each { |au| access[au.institution_code] = au.access_url }
Expand Down
46 changes: 46 additions & 0 deletions app/models/document/date_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

# Date Validation
#
# ex. Bad date field type value
# "foo" is not a date
# "2023-12-5" is a date
class Document
# DateValidator
class DateValidator < ActiveModel::Validator
def validate(record)
# Assume true
valid_date = true

date_elements = Element.where(field_type: "date")

# Sane date values?
date_elements.each do |element|
unless record.send(element.solr_field).nil?
Rails.logger.debug("Date Validator")
Rails.logger.debug("Dates: #{record.send(element.solr_field).inspect}")
record.send(element.solr_field).each do |date|
Rails.logger.debug("\nDate: #{date}")
valid_date = proper_date(record, element, date, valid_date)

break if !valid_date
end
end
end

valid_date
end

def proper_date(record, element, date, valid_date)
if date.blank?
valid_date = true
elsif date.class != Date
valid_date = false
record.errors.add(GeoblacklightAdmin::Schema.instance.solr_fields[element.to_sym], "Bad date field type.")
end

Rails.logger.debug("#{date} - #{valid_date}")
valid_date
end
end
end
1 change: 1 addition & 0 deletions app/models/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Element < ApplicationRecord
text
integer
boolean
date
datetime
].freeze

Expand Down
Loading

0 comments on commit 1da9fbd

Please sign in to comment.