Skip to content

Commit

Permalink
Adds a permissive schema to the Fedora Valkyrie adapter (#6332). (#6338)
Browse files Browse the repository at this point in the history
* Adds a permissive schema to the Fedora Valkyrie adapter (#6332).

* convert keys to symbols.

* Adds internal attributes.

* Adds warning of multiple assignments.

* Include predicate details in warning and only warn if the predicates do not match; sort internals

---------

Co-authored-by: Daniel Pierce <dlpierce@indiana.edu>
  • Loading branch information
bwatson78 and dlpierce committed Oct 6, 2023
1 parent bf3c903 commit c5db7f6
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .dassie/config/metadata/collection_resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ attributes:
form:
primary: true
multiple: true
predicate: http://hyrax-example.com/target_audience
department:
type: string
form:
primary: true
predicate: http://hyrax-example.com/department
course:
type: string
form:
primary: false
predicate: http://hyrax-example.com/course
8 changes: 8 additions & 0 deletions .dassie/config/metadata/monograph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,41 @@
attributes:
monograph_title:
type: string
predicate: http://hyrax-example.com/monograph_title
record_info:
type: string
form:
required: true
primary: true
index_keys:
- "record_info_tesim"
predicate: http://hyrax-example.com/record_info
place_of_publication:
type: string
form:
required: false
primary: true
predicate: http://hyrax-example.com/place_of_publication
genre:
type: string
form:
primary: true
predicate: http://hyrax-example.com/genre
series_title:
type: string
form:
primary: false
predicate: http://hyrax-example.com/series_title
target_audience:
type: string
form:
multiple: true
predicate: http://hyrax-example.com/target_audience
table_of_contents:
type: string
form:
multiple: false
predicate: http://hyrax-example.com/table_of_contents
date_of_issuance:
type: string
predicate: http://hyrax-example.com/date_of_issuance
1 change: 1 addition & 0 deletions .dassie/config/metadata/sample_metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
attributes:
sample_attribute:
type: string
predicate: http://hyrax-example.com/sample_attribute
3 changes: 2 additions & 1 deletion .koppie/config/initializers/1_valkyrie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
Valkyrie::Persistence::Fedora::MetadataAdapter.new(
connection: ::Ldp::Client.new(Hyrax.config.fedora_connection_builder.call(
ENV.fetch('FCREPO_URL') { "http://localhost:8080/fcrepo/rest" })),
base_path: Rails.env, #, schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new(title: RDF::URI("http://example.com/title"))
base_path: Rails.env,
schema: Valkyrie::Persistence::Fedora::PermissiveSchema.new(Hyrax::SimpleSchemaLoader.new.permissive_schema_for_valkrie_adapter),
fedora_version: 6
), :nurax_fedora_metadata_adapter
)
Expand Down
25 changes: 25 additions & 0 deletions .koppie/config/metadata/collection_resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# index key names, and form properties.
#
# Attributes must have a type but all other configuration options are optional.
# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes
# must be placed here.
#
# attributes:
# attribute_name:
Expand All @@ -27,6 +29,7 @@ attributes:
primary: true
index_keys:
- "description_tesim"
predicate: http://purl.org/dc/elements/1.1/description
creator:
type: string
multiple: true
Expand All @@ -35,34 +38,39 @@ attributes:
primary: false
index_keys:
- "creator_tesim"
predicate: http://purl.org/dc/elements/1.1/creator
rights_statement:
type: string
multiple: true
form:
primary: false
index_keys:
- "rights_statement_tesim"
predicate: http://www.europeana.eu/schemas/edm/rights
abstract:
type: string
multiple: true
form:
primary: false
index_keys:
- "abstract_tesim"
predicate: http://purl.org/dc/terms/abstract
access_right:
type: string
multiple: true
form:
primary: false
index_keys:
- "access_right_tesim"
predicate: http://purl.org/dc/terms/accessRights
alternative_title:
type: string
multiple: true
form:
primary: false
index_keys:
- "alternative_title_tesim"
predicate: http://purl.org/dc/terms/alternative
based_near:
type: string
multiple: true
Expand All @@ -71,32 +79,38 @@ attributes:
index_keys:
- "based_near_sim"
- "based_near_tesim"
predicate: http://xmlns.com/foaf/0.1/based_near
bibliographic_citation:
type: string
multiple: true
predicate: http://purl.org/dc/terms/bibliographicCitation
contributor:
type: string
multiple: true
form:
primary: false
index_keys:
- "contributor_tesim"
predicate: http://purl.org/dc/elements/1.1/contributor
date_created:
type: date_time
multiple: true
form:
primary: false
index_keys:
- "date_created_tesim"
predicate: http://purl.org/dc/terms/created
identifier:
type: string
multiple: true
form:
primary: false
index_keys:
- "identifier_tesim"
predicate: http://purl.org/dc/terms/identifier
import_url:
type: string
predicate: http://scholarsphere.psu.edu/ns#importUrl
keyword:
type: string
multiple: true
Expand All @@ -105,42 +119,49 @@ attributes:
- "keyword_tesim"
form:
primary: false
predicate: http://schema.org/keywords
publisher:
type: string
multiple: true
form:
primary: false
index_keys:
- "publisher_tesim"
predicate: http://purl.org/dc/elements/1.1/publisher
label:
type: string
form:
primary: false
index_keys:
- "label_tesim"
predicate: info:fedora/fedora-system:def/model#downloadFilename
language:
type: string
multiple: true
form:
primary: false
index_keys:
- "language_tesim"
predicate: http://purl.org/dc/elements/1.1/language
license:
type: string
multiple: true
form:
primary: false
index_keys:
- "license_tesim"
predicate: http://purl.org/dc/terms/license
relative_path:
type: string
predicate: http://scholarsphere.psu.edu/ns#relativePath
related_url:
type: string
multiple: true
form:
primary: false
index_keys:
- "related_url_tesim"
predicate: http://www.w3.org/2000/01/rdf-schema#seeAlso
resource_type:
type: string
multiple: true
Expand All @@ -149,20 +170,23 @@ attributes:
index_keys:
- "resource_type_sim"
- "resource_type_tesim"
predicate: http://purl.org/dc/terms/type
rights_notes:
type: string
multiple: true
form:
primary: false
index_keys:
- "rights_notes_tesim"
predicate: http://purl.org/dc/elements/1.1/rights
source:
type: string
multiple: true
form:
primary: false
index_keys:
- "source_tesim"
predicate: http://purl.org/dc/terms/source
subject:
type: string
multiple: true
Expand All @@ -171,3 +195,4 @@ attributes:
- "subject_tesim"
form:
primary: false
predicate: http://purl.org/dc/elements/1.1/subject
2 changes: 2 additions & 0 deletions .koppie/config/metadata/generic_work.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# index key names, and form properties.
#
# Attributes must have a type but all other configuration options are optional.
# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes
# must be placed here.
#
# attributes:
# attribute_name:
Expand Down
10 changes: 10 additions & 0 deletions .koppie/config/metadata/monograph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# index key names, and form properties.
#
# Attributes must have a type but all other configuration options are optional.
# Please note: If using Valkyrie's Fedora Metadata Adapter, predicates for attributes
# must be placed here.
#
# attributes:
# attribute_name:
Expand All @@ -23,33 +25,41 @@
attributes:
monograph_title:
type: string
predicate: http://hyrax-example.com/monograph_title
record_info:
type: string
form:
required: true
primary: true
index_keys:
- "record_info_tesim"
predicate: http://hyrax-example.com/record_info
place_of_publication:
type: string
form:
required: false
primary: true
predicate: http://hyrax-example.com/place_of_publication
genre:
type: string
form:
primary: true
predicate: http://hyrax-example.com/genre
series_title:
type: string
form:
primary: false
predicate: http://hyrax-example.com/series_title
target_audience:
type: string
form:
multiple: true
predicate: http://hyrax-example.com/target_audience
table_of_contents:
type: string
form:
multiple: false
predicate: http://hyrax-example.com/table_of_contents
date_of_issuance:
type: string
predicate: http://hyrax-example.com/date_of_issuance
31 changes: 31 additions & 0 deletions app/services/hyrax/simple_schema_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def index_rules_for(schema:)
end
end

def permissive_schema_for_valkrie_adapter
metadata_files.each_with_object({}) do |schema_name, ret_hsh|
predicate_pairs(ret_hsh, schema_name)
end
end

##
# @api private
class AttributeDefinition
Expand Down Expand Up @@ -154,5 +160,30 @@ def config_paths(schema_name)
def config_search_paths
[Rails.root, Hyrax::Engine.root]
end

def metadata_files
file_name_arr = []
config_search_paths.each { |root_path| file_name_arr += Dir.entries(root_path.to_s + "/config/metadata/") }
file_name_arr.reject { |fn| !fn.include?('.yaml') }.uniq.map { |y| y.gsub('.yaml', '') }
end

def predicate_pairs(ret_hsh, schema_name)
schema_config(schema_name)['attributes'].each do |name, config|
predicate = RDF::URI(config['predicate'])
if ret_hsh[name].blank?
ret_hsh[name.to_sym] = predicate
elsif ret_hsh[name] != predicate
multiple_predicate_message(name, ret_hsh[name], predicate)
end
end
end

def multiple_predicate_message(name, existing, incoming)
message = "The attribute of #{name} has been assigned a predicate multiple times " \
"within the metadata YAMLs. Please be aware that once the attribute's " \
"predicate value is first assigned, any other value will be ignored. " \
"The existing value is #{existing} preventing the use of #{incoming}"
Hyrax.logger.warn(message)
end
end
end
Loading

0 comments on commit c5db7f6

Please sign in to comment.