-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated schema yaml and included further items
- Loading branch information
Martin Simpson
committed
Feb 4, 2024
1 parent
7b84abc
commit a34ba36
Showing
21 changed files
with
808 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/forms/concerns/hyku_knapsack/collection_form_behavior.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module HykuKnapsack | ||
module CollectionFormBehavior | ||
extend ActiveSupport::Concern | ||
|
||
include HykuKnapsack::PersonOrOrganizationFormBehavior | ||
|
||
# TODO: extract duplicate code (from JSONFieldsActor) out into a service class? | ||
# rubocop:disable Metrics/BlockLength | ||
class_methods do | ||
def model_attributes(form_params) | ||
super.tap do |model_attributes| | ||
[:creator, :contributor].each do |field| | ||
if name_blank?(field, model_attributes[field]&.map(&:to_h)) || recursive_blank?(model_attributes[field]&.map(&:to_h)) | ||
model_attributes.delete(field) | ||
else | ||
model_attributes[field] = model_attributes[field].to_json | ||
end | ||
model_attributes[field] = Array(model_attributes[field]) if multiple?(field) | ||
end | ||
end | ||
end | ||
|
||
def name_blank?(field, obj) | ||
return false unless field.in? [:creator, :contributor, :editor] | ||
recursive_blank?(Array(obj).map { |o| o.reject { |k, _v| k == "#{field}_name_type" } }) | ||
end | ||
|
||
def recursive_blank?(obj) | ||
case obj | ||
when Hash | ||
obj.values.all? { |o| recursive_blank?(o) } | ||
when Array | ||
obj.all? { |o| recursive_blank?(o) } | ||
else | ||
obj.blank? | ||
end | ||
end | ||
end | ||
# rubocop:enable Metrics/BlockLength | ||
|
||
# User collections will error without this, as _title is used in for works and collections | ||
def schema_driven? | ||
false | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
app/forms/concerns/hyku_knapsack/generic_work_form_overrides.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module HykuKnapsack | ||
module GenericWorkFormOverrides | ||
extend ActiveSupport::Concern | ||
|
||
include ::HykuKnapsack::WorkForm | ||
|
||
included do | ||
# version is used in the show page but populated by version_number from the edit and new form | ||
add_terms %i[title resource_type creator alt_title contributor rendering_ids abstract date_published media | ||
duration institution org_unit project_name funder fndr_project_ref event_title event_location | ||
event_date series_name book_title editor journal_title alternative_journal_title volume edition | ||
version_number issue pagination article_num publisher place_of_publication isbn issn eissn | ||
current_he_institution date_accepted date_submitted official_link related_url related_exhibition | ||
related_exhibition_venue related_exhibition_date language license rights_statement rights_holder doi | ||
qualification_name qualification_level alternate_identifier related_identifier refereed keyword dewey | ||
library_of_congress_classification add_info] | ||
self.required_fields = %i[title resource_type creator institution date_published] | ||
|
||
# These includes are after add_terms because they add terms | ||
include Hyrax::DOI::DOIFormBehavior | ||
include Hyrax::DOI::DataCiteDOIFormBehavior | ||
|
||
def primary_terms | ||
super - %i[license] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module HykuKnapsack | ||
module ImageFormOverrides | ||
extend ActiveSupport::Concern | ||
|
||
include ::HykuKnapsack::WorkForm | ||
|
||
included do | ||
add_terms %i[title resource_type creator alt_title contributor rendering_ids abstract date_published media | ||
duration institution org_unit project_name funder fndr_project_ref | ||
publisher place_of_publication date_accepted date_submitted official_link related_url | ||
related_exhibition related_exhibition_venue related_exhibition_date language license rights_statement | ||
rights_holder doi alternate_identifier related_identifier refereed keyword dewey | ||
library_of_congress_classification add_info] | ||
self.required_fields = %i[title resource_type creator institution date_published] | ||
|
||
# These must be added after the terms are defined | ||
include Hyrax::DOI::DOIFormBehavior | ||
include Hyrax::DOI::DataCiteDOIFormBehavior | ||
end | ||
end | ||
end |
57 changes: 57 additions & 0 deletions
57
app/forms/concerns/hyku_knapsack/person_or_organization_form_behavior.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module HykuKnapsack | ||
module PersonOrOrganizationFormBehavior | ||
extend ActiveSupport::Concern | ||
|
||
# Helper methods for JSON fields | ||
def creator_list | ||
person_or_organization_list(:creator) | ||
end | ||
|
||
def contributor_list | ||
person_or_organization_list(:contributor) | ||
end | ||
|
||
# rubocop:disable Metrics/BlockLength | ||
class_methods do | ||
# Group all params here so save on boiler plate | ||
def build_permitted_params | ||
super.tap do |permitted_params| | ||
permitted_params << creator_fields | ||
permitted_params << contributor_fields | ||
end | ||
end | ||
|
||
def creator_fields | ||
{ | ||
creator: [ | ||
:creator_organization_name, :creator_given_name, :creator_middle_name, :creator_family_name, | ||
:creator_name_type, :creator_orcid, :creator_isni, :creator_ror, :creator_grid, :creator_wikidata, | ||
:creator_suffix, :creator_institution, :creator_institutional_email, :creator_computing_id, | ||
:creator_profile_visibility, creator_institution: [], creator_role: [], creator_institutional_relationship: [] | ||
] | ||
} | ||
end | ||
|
||
def contributor_fields | ||
{ | ||
contributor: [ | ||
:contributor_organization_name, :contributor_given_name, :contributor_middle_name, | ||
:contributor_family_name, :contributor_name_type, :contributor_orcid, :contributor_isni, :contributor_ror, | ||
:contributor_grid, :contributor_wikidata, :contributor_suffix, :contributor_type, :contributor_institution, | ||
contributor_institution: [], contributor_role: [], contributor_institutional_relationship: [] | ||
] | ||
} | ||
end | ||
end | ||
|
||
private | ||
|
||
def person_or_organization_list(field) | ||
# Return empty hash to ensure that it gets rendered at least once | ||
return [{}] if send(field)&.first.blank? | ||
JSON.parse(send(field).first) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# frozen_string_literal: true | ||
|
||
module HykuKnapsack | ||
module WorkBase | ||
extend ActiveSupport::Concern | ||
|
||
include Hyrax::Autopopulation::AutopopulationProperty | ||
include HykuKnapsack::TaskMaster::WorkBehavior | ||
|
||
# TODO: Review indexing and switch to mostly _ssim instead of _tesim | ||
# rubocop:disable Metrics/BlockLength | ||
included do | ||
# From SharedMetadata | ||
property :official_link, predicate: ::RDF::Vocab::SCHEMA.url, multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
# From BasicMetadataDecorator | ||
property :institution, predicate: ::RDF::Vocab::ORG.organization do |index| | ||
index.as :stored_searchable, :facetable | ||
end | ||
|
||
property :org_unit, predicate: ::RDF::Vocab::ORG.OrganizationalUnit do |index| | ||
index.as :stored_searchable, :facetable | ||
end | ||
|
||
property :funder, predicate: ::RDF::Vocab::MARCRelators.fnd do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
# FIXME: Dates should be indexed as dates or at least _ssim not _tesim | ||
property :date_published, predicate: ::RDF::Vocab::DC.available, multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :date_accepted, predicate: ::RDF::Vocab::DC.dateAccepted, multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :date_submitted, predicate: ::RDF::Vocab::Bibframe.originDate, multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :project_name, predicate: ::RDF::Vocab::BF2.term(:CollectiveTitle) do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :rights_holder, predicate: ::RDF::Vocab::DC.rightsHolder do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :abstract, predicate: ::RDF::Vocab::DC.abstract, multiple: false do |index| | ||
index.type :text | ||
index.as :stored_searchable | ||
end | ||
|
||
property :alternate_identifier, predicate: ::RDF::Vocab::BF2.term(:Local) do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :related_identifier, predicate: ::RDF::Vocab::BF2.identifiedBy do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :library_of_congress_classification, predicate: ::RDF::Vocab::BF2.term(:ClassificationLcc) do |index| | ||
index.as :stored_searchable, :facetable | ||
end | ||
|
||
property :dewey, predicate: ::RDF::Vocab::SCHEMA.CategoryCode, multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :note, predicate: ::RDF::Vocab::MODS.note, multiple: true do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
# property :file_availability, predicate: ::RDF::Vocab::SCHEMA.ItemAvailability do |index| | ||
# index.as :stored_searchable, :facetable | ||
# end | ||
|
||
property :source_identifier, predicate: ::RDF::Vocab::PROV.wasDerivedFrom, multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
class_attribute :json_fields, :date_fields | ||
self.json_fields = %i[creator contributor funder alternate_identifier related_identifier] | ||
self.date_fields = %i[date_published date_accepted date_submitted] | ||
end | ||
# rubocop:enable Metrics/BlockLength | ||
|
||
def schema_driven? | ||
false | ||
end | ||
end | ||
end |
Oops, something went wrong.