Skip to content

Commit 382c6d9

Browse files
committed
fix bugs, add db seed
1 parent 7e06f18 commit 382c6d9

File tree

11 files changed

+207
-13
lines changed

11 files changed

+207
-13
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
m3_version: 1.0.beta2
3+
profile:
4+
date_modified: '2024-06-01'
5+
responsibility: https://samvera.org
6+
responsibility_statement: Hyrax Initial Profile
7+
type:
8+
version: 1
9+
classes:
10+
GenericWorkResource:
11+
display_label: Generic Work
12+
Monograph:
13+
display_label: Monograph
14+
AdminSet:
15+
diplay_label: AdminSet
16+
AdminSetResource:
17+
diplay_label: AdministrativeSet
18+
Collection:
19+
display_label: Collection
20+
CollectionResource:
21+
display_label: PcdmCollection
22+
Hyrax::FileSet:
23+
display_label: FileSet
24+
contexts:
25+
flexible_context:
26+
display_label: Flexible Metadata Example
27+
mappings:
28+
blacklight:
29+
name: Additional Blacklight Solr Mappings
30+
metatags:
31+
name: Metatags
32+
mods_oai_pmh:
33+
name: MODS OAI PMH
34+
qualified_dc_pmh:
35+
name: Qualified DC OAI PMH
36+
simple_dc_pmh:
37+
name: Simple DC OAI PMH
38+
properties:
39+
title:
40+
available_on:
41+
class:
42+
- AdminSetResource
43+
- AdminSet
44+
- Hyrax::FileSet
45+
- CollectionResource
46+
- GenericWorkResource
47+
- Monograph
48+
cardinality:
49+
minimum: 0
50+
multi_value: true
51+
controlled_values:
52+
format: http://www.w3.org/2001/XMLSchema#string
53+
sources:
54+
- 'null'
55+
definition:
56+
default: Enter a standardized title for display. If only one
57+
title is needed, transcribe the title from the source
58+
itself.
59+
display_label:
60+
default: Title
61+
index_documentation: displayable, searchable
62+
indexing:
63+
- 'title_sim'
64+
- 'title_tesim'
65+
form:
66+
required: true
67+
primary: true
68+
multi_value: true
69+
mappings:
70+
metatags: twitter:title, og:title
71+
mods_oai_pmh: mods:titleInfo/mods:title
72+
qualified_dc_pmh: dcterms:title
73+
simple_dc_pmh: dc:title
74+
property_uri: http://purl.org/dc/terms/title
75+
range: http://www.w3.org/2001/XMLSchema#string
76+
requirement: required
77+
sample_values:
78+
- Pencil drawn portrait study of woman
79+
date_modified:
80+
available_on:
81+
class:
82+
- AdminSetResource
83+
- AdminSet
84+
- Hyrax::FileSet
85+
- CollectionResource
86+
- GenericWorkResource
87+
- Monograph
88+
cardinality:
89+
minimum: 0
90+
maximum: 1
91+
multi_value: false
92+
display_label:
93+
default: Date Modified
94+
property_uri: http://purl.org/dc/terms/modified
95+
range: http://www.w3.org/2001/XMLSchema#dateTime
96+
sample_values:
97+
- "2024-06-06 21:06:51 +0000"
98+
date_uploaded:
99+
available_on:
100+
class:
101+
- AdminSetResource
102+
- AdminSet
103+
- Hyrax::FileSet
104+
- CollectionResource
105+
- GenericWorkResource
106+
- Monograph
107+
cardinality:
108+
minimum: 0
109+
maximum: 1
110+
multi_value: false
111+
display_label:
112+
default: Date Uploaded
113+
property_uri: http://purl.org/dc/terms/dateSubmitted
114+
range: http://www.w3.org/2001/XMLSchema#dateTime
115+
sample_values:
116+
- "2024-06-06 21:06:51 +0000"
117+
depositor:
118+
available_on:
119+
class:
120+
- AdminSetResource
121+
- AdminSet
122+
- Hyrax::FileSet
123+
- CollectionResource
124+
- GenericWorkResource
125+
- Monograph
126+
cardinality:
127+
minimum: 0
128+
maximum: 1
129+
multi_value: false
130+
controlled_values:
131+
format: http://www.w3.org/2001/XMLSchema#string
132+
sources:
133+
- 'null'
134+
display_label:
135+
default: Depositor
136+
index_documentation: searchable
137+
indexing:
138+
- 'depositor_tesim'
139+
property_uri: http://id.loc.gov/vocabulary/relators/dpt
140+
range: http://www.w3.org/2001/XMLSchema#string
141+
sample_values:
142+
- Julie Allinson
143+
creator:
144+
available_on:
145+
class:
146+
- Hyrax::FileSet
147+
cardinality:
148+
minimum: 1
149+
multi_value: true
150+
controlled_values:
151+
format: http://www.w3.org/2001/XMLSchema#string
152+
sources:
153+
- 'null'
154+
display_label:
155+
default: Creator
156+
index_documentation: searchable
157+
indexing:
158+
- 'creator_tesim'
159+
property_uri: http://purl.org/dc/elements/1.1/creator
160+
range: http://www.w3.org/2001/XMLSchema#string
161+
sample_values:
162+
- Julie Allinson

.dassie/db/migrate/20240606205215_create_hyrax_flexible_schemas.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class CreateHyraxFlexibleSchemas < ActiveRecord::Migration[6.1]
22
def change
33
create_table :hyrax_flexible_schemas do |t|
4-
t.string :version, index: { unique: true }
54
t.text :profile
65

76
t.timestamps

.dassie/db/schema.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@
173173
end
174174

175175
create_table "hyrax_flexible_schemas", force: :cascade do |t|
176-
t.string "version"
177176
t.text "profile"
178177
t.datetime "created_at", precision: 6, null: false
179178
t.datetime "updated_at", precision: 6, null: false

app/models/concerns/hyrax/flexibility.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def new(attributes = default_attributes, safe = false, &block) # rubocop:disable
5959

6060
## Read the schema from the database and load the correct schemas for the instance in to the class
6161
def load(attributes, safe = false)
62-
attributes[:schema_version] ||= Hyrax::FlexibleSchema.order('created_at DESC').pick(:version)
62+
attributes[:schema_version] ||= Hyrax::FlexibleSchema.order('id DESC').pick(:id)
6363
struct = allocate
6464
schema_version = attributes[:schema_version]
6565
struct.singleton_class.attributes(Hyrax::Schema(self, schema_version:).attributes)

app/models/hyrax/flexible_schema.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
class Hyrax::FlexibleSchema < ApplicationRecord
22
serialize :profile, coder: YAML
33

4+
def title
5+
"#{profile['profile']['responsibility_statement']} - version #{id}"
6+
end
7+
48
def attributes_for(class_name)
59
class_names[class_name]
610
end
@@ -22,8 +26,8 @@ def class_names
2226
end
2327

2428
def values_map(values)
25-
values['type'] = lookup_type(value['range'])
26-
values['predicate'] = value['property_uri']
29+
values['type'] = lookup_type(values['range'])
30+
values['predicate'] = values['property_uri']
2731
values['index_keys'] = values['indexing']
2832
values['multiple'] = values['multi_value']
2933
values

app/services/hyrax/m3_schema_loader.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ class M3SchemaLoader < Hyrax::SchemaLoader
1414
# @param [#to_s] schema_name
1515
# @return [Enumerable<AttributeDefinition]
1616
def definitions(schema_name, version)
17-
Hyrax::FlexibleSchema.find_by(version: version).attributes_for(schema_name).map do |name, config|
17+
Hyrax::FlexibleSchema.find(version).attributes_for(schema_name).map do |name, config|
1818
AttributeDefinition.new(name, config)
1919
end
20+
rescue NoMethodError
21+
raise UndefinedSchemaError, "Flexible schema not found in version #{version} for #{schema_name}"
2022
end
2123
end
2224
end

app/services/hyrax/schema_loader.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ module Hyrax
88
#
99
# @see config/metadata/basic_metadata.yaml for an example configuration
1010
class SchemaLoader
11+
class UndefinedSchemaError < ArgumentError; end
12+
1113
##
1214
# @param [Symbol] schema
1315
#
1416
# @return [Hash<Symbol, Dry::Types::Type>] a map from attribute names to
1517
# types
1618
def attributes_for(schema:, version: 1)
17-
definitions(schema).each_with_object({}) do |definition, hash|
19+
definitions(schema, version).each_with_object({}) do |definition, hash|
1820
hash[definition.name] = definition.type.meta(definition.config)
1921
end
2022
end
@@ -24,7 +26,7 @@ def attributes_for(schema:, version: 1)
2426
#
2527
# @return [Hash{Symbol => Hash{Symbol => Object}}]
2628
def form_definitions_for(schema:, version: 1)
27-
definitions(schema).each_with_object({}) do |definition, hash|
29+
definitions(schema, version).each_with_object({}) do |definition, hash|
2830
next if definition.form_options.empty?
2931

3032
hash[definition.name] = definition.form_options
@@ -36,7 +38,7 @@ def form_definitions_for(schema:, version: 1)
3638
#
3739
# @return [{Symbol => Symbol}] a map from index keys to attribute names
3840
def index_rules_for(schema:, version: 1)
39-
definitions(schema).each_with_object({}) do |definition, hash|
41+
definitions(schema, version).each_with_object({}) do |definition, hash|
4042
definition.index_keys.each do |key|
4143
hash[key] = definition.name
4244
end

app/services/hyrax/simple_schema_loader.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ def permissive_schema_for_valkrie_adapter
1414
end
1515
end
1616

17-
class UndefinedSchemaError < ArgumentError; end
18-
1917
private
2018

2119
##
2220
# @param [#to_s] schema_name
2321
# @return [Enumerable<AttributeDefinition]
24-
def definitions(schema_name)
22+
def definitions(schema_name, _version)
2523
schema_config(schema_name)['attributes'].map do |name, config|
2624
AttributeDefinition.new(name, config)
2725
end

app/utils/hyrax/required_data_seeder.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def initialize(logger: Logger.new(STDOUT))
1414
end
1515

1616
def generate_seed_data
17+
Hyrax::RequiredDataSeeders::FlexibleProfileSeeder.generate_seeds(logger: logger) if ENV.fetch('HYRAX_FLEXIBLE', false)
1718
Hyrax::RequiredDataSeeders::CollectionTypeSeeder.generate_seeds(logger: logger)
1819
Hyrax::RequiredDataSeeders::CollectionSeeder.generate_seeds(logger: logger)
1920
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
module Hyrax
4+
module RequiredDataSeeders
5+
# This class was created for use in rake tasks and db/seeds.rb. It generates
6+
# collections that are required for all Hyrax applications.
7+
#
8+
# Seeders of required data are non-destructive. If the data already exists,
9+
# it will not be replaced.
10+
class FlexibleProfileSeeder
11+
class << self
12+
attr_accessor :logger
13+
14+
def generate_seeds(logger: Logger.new(STDOUT))
15+
@logger = logger
16+
17+
logger.info("Adding required collections...")
18+
19+
flexible_schema = Hyrax::FlexibleSchema.first_or_create do |f|
20+
f.profile = YAML.safe_load_file(Rails.root.join('config', 'metadata', 'm3_profile.yaml'))
21+
end
22+
23+
logger.info " #{flexible_schema.title} -- FOUND OR CREATED"
24+
end
25+
end
26+
end
27+
end
28+
end

0 commit comments

Comments
 (0)