cul_scv_hydra 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/bag_aggregator.rb +16 -0
- data/app/models/content_aggregator.rb +16 -0
- data/app/models/dcdocument.rb +9 -0
- data/app/models/generic_aggregator.rb +16 -0
- data/app/models/generic_object.rb +16 -0
- data/app/models/jp2_image_aggregator.rb +38 -0
- data/app/models/mets_structured_aggregator.rb +16 -0
- data/app/models/resource.rb +59 -0
- data/app/models/static_audio_aggregator.rb +21 -0
- data/app/models/static_image_aggregator.rb +21 -0
- data/config/fedora.yml +6 -0
- data/config/predicate_mappings.yml +56 -0
- data/config/solr.yml +15 -0
- data/config/solr_mappings.yml +26 -0
- data/config/solr_value_maps.yml +29 -0
- data/lib/cul_scv_hydra.rb +14 -0
- data/lib/cul_scv_hydra/access_controls_enforcement.rb +53 -0
- data/lib/cul_scv_hydra/active_fedora.rb +18 -0
- data/lib/cul_scv_hydra/active_fedora/model.rb +8 -0
- data/lib/cul_scv_hydra/active_fedora/model/aggregator.rb +45 -0
- data/lib/cul_scv_hydra/active_fedora/model/common.rb +221 -0
- data/lib/cul_scv_hydra/active_fedora/model/dcdocument.rb +43 -0
- data/lib/cul_scv_hydra/active_fedora/model/resource.rb +79 -0
- data/lib/cul_scv_hydra/controllers.rb +13 -0
- data/lib/cul_scv_hydra/controllers/aggregates.rb +95 -0
- data/lib/cul_scv_hydra/controllers/aggregator_controller_helper.rb +27 -0
- data/lib/cul_scv_hydra/controllers/catalog.rb +13 -0
- data/lib/cul_scv_hydra/controllers/content_aggregators.rb +83 -0
- data/lib/cul_scv_hydra/controllers/datastreams.rb +146 -0
- data/lib/cul_scv_hydra/controllers/helpers.rb +11 -0
- data/lib/cul_scv_hydra/controllers/helpers/active_fedora_helper_behavior.rb +9 -0
- data/lib/cul_scv_hydra/controllers/helpers/application_helper_behavior.rb +17 -0
- data/lib/cul_scv_hydra/controllers/helpers/dc_metadata_helper_behavior.rb +9 -0
- data/lib/cul_scv_hydra/controllers/helpers/hydra_assets_helper_behavior.rb +46 -0
- data/lib/cul_scv_hydra/controllers/helpers/hydra_autocomplete_helper_behavior.rb +35 -0
- data/lib/cul_scv_hydra/controllers/helpers/hydra_uploader_helper_behavior.rb +34 -0
- data/lib/cul_scv_hydra/controllers/helpers/resources_helper_behavior.rb +160 -0
- data/lib/cul_scv_hydra/controllers/resources.rb +162 -0
- data/lib/cul_scv_hydra/controllers/static_image_aggregators.rb +106 -0
- data/lib/cul_scv_hydra/controllers/suggestions.rb +127 -0
- data/lib/cul_scv_hydra/controllers/terms.rb +152 -0
- data/lib/cul_scv_hydra/engine.rb +9 -0
- data/lib/cul_scv_hydra/om.rb +11 -0
- data/lib/cul_scv_hydra/om/dc_metadata.rb +70 -0
- data/lib/cul_scv_hydra/om/scv_mods_document.rb +132 -0
- data/lib/cul_scv_hydra/om/standard_mods.rb +111 -0
- data/lib/cul_scv_hydra/solrizer.rb +12 -0
- data/lib/cul_scv_hydra/solrizer/extractor.rb +27 -0
- data/lib/cul_scv_hydra/solrizer/field_mapper.rb +30 -0
- data/lib/cul_scv_hydra/solrizer/terminology_based_solrizer.rb +112 -0
- data/lib/cul_scv_hydra/solrizer/value_mapper.rb +35 -0
- data/lib/cul_scv_hydra/version.rb +10 -0
- metadata +333 -0
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'cul_scv_hydra'
|
2
|
+
require 'json'
|
3
|
+
module Cul::Scv::Hydra::Controllers
|
4
|
+
module Terms
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
include Blacklight::SolrHelper
|
8
|
+
include MediaShelf::ActiveFedoraHelper
|
9
|
+
before_filter :require_solr, :only=>[:index]
|
10
|
+
end
|
11
|
+
|
12
|
+
def index
|
13
|
+
if params[:layout] == "false"
|
14
|
+
layout = false
|
15
|
+
end
|
16
|
+
if params[:term_id]
|
17
|
+
@solr_name = solr_name(params[:term_id])
|
18
|
+
else
|
19
|
+
@solr_name = params[:solr_name]
|
20
|
+
end
|
21
|
+
@terms = term_values
|
22
|
+
render :action=>params[:action], :layout=>layout
|
23
|
+
end
|
24
|
+
|
25
|
+
def solr_name(term_id)
|
26
|
+
if term_id.nil?
|
27
|
+
raise "Cannot provide suggestions without a term name"
|
28
|
+
end
|
29
|
+
field_key = field_key_from(term_id, Cul::Scv::Hydra::Om::ModsDocument.terminology)
|
30
|
+
get_solr_name(field_key, Cul::Scv::Hydra::Om::ModsDocument)
|
31
|
+
end
|
32
|
+
def term_values
|
33
|
+
if @solr_name.nil?
|
34
|
+
logger.debug "no solr field name, return nil for term values"
|
35
|
+
return nil
|
36
|
+
end
|
37
|
+
stub = params[:term_value]
|
38
|
+
solr_params = {}
|
39
|
+
solr_params['wt'] = 'json'
|
40
|
+
solr_params['terms'] = 'true'
|
41
|
+
solr_params['terms.fl'] = @solr_name
|
42
|
+
if stub
|
43
|
+
solr_params['terms.lower'] = stub
|
44
|
+
solr_params['terms.lower.incl'] = false
|
45
|
+
solr_params['terms.prefix'] = stub
|
46
|
+
solr_params['terms.sort'] = 'index'
|
47
|
+
else
|
48
|
+
solr_params['terms.sort'] = params.fetch(:sort,'count')
|
49
|
+
solr_params['terms.limit'] = -1
|
50
|
+
end
|
51
|
+
logger.debug solr_params.inspect
|
52
|
+
solr_response = Blacklight.solr.get 'terms', {:params => solr_params}
|
53
|
+
result = []
|
54
|
+
hash = {}
|
55
|
+
(1...solr_response['terms'].length).step(2) { |ix|
|
56
|
+
_t = solr_response['terms'][ix]
|
57
|
+
(0..._t.length).step(2) { |jx|
|
58
|
+
result << [_t[jx], _t[jx + 1]]
|
59
|
+
}
|
60
|
+
}
|
61
|
+
logger.debug result.inspect
|
62
|
+
return result
|
63
|
+
end
|
64
|
+
|
65
|
+
## field_key_from(field_name) to reverse this method from HydraFedoraMetadataHelper
|
66
|
+
# def field_name_for(field_key)
|
67
|
+
# if field_key.kind_of?(Array)
|
68
|
+
# return OM::XML::Terminology.term_hierarchical_name(*field_key)
|
69
|
+
# else
|
70
|
+
# field_key.to_s
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
|
74
|
+
def field_key_from(field_name, terminology)
|
75
|
+
# this is a hack, but necessary until/unless OM generates names differently
|
76
|
+
candidates = field_name.split('__')
|
77
|
+
field_key = []
|
78
|
+
candidates.each_with_index { |candidate, ix|
|
79
|
+
if (candidates[ix + 1] and candidates[ix + 1].match(/\d+/))
|
80
|
+
field_key << {OM.destringify(candidate) => Integer(candidates.delete_at(ix + 1))}
|
81
|
+
else
|
82
|
+
field_key << OM.destringify(candidate)
|
83
|
+
end
|
84
|
+
}
|
85
|
+
logger.debug field_key.inspect
|
86
|
+
field_key
|
87
|
+
end
|
88
|
+
|
89
|
+
# ** largely copied from ActiveFedora::NokogiriDatastream.get_values **
|
90
|
+
def get_solr_name(term_pointer, dsClass)
|
91
|
+
term = dsClass.terminology.retrieve_term(*OM.pointers_to_flat_array(term_pointer, false))
|
92
|
+
names = []
|
93
|
+
if is_hierarchical_term_pointer?(*term_pointer)
|
94
|
+
bases = []
|
95
|
+
#add first item in term_pointer as start of bases
|
96
|
+
# then iterate through possible nodes that might exist
|
97
|
+
term_pointer.first.kind_of?(Hash) ? bases << term_pointer.first.keys.first : bases << term_pointer.first
|
98
|
+
for i in 1..(term_pointer.length-1)
|
99
|
+
#iterate in reverse so that we can modify the bases array while iterating
|
100
|
+
(bases.length-1).downto(0) do |j|
|
101
|
+
current_last = (term_pointer[i].kind_of?(Hash) ? term_pointer[i].keys.first : term_pointer[i])
|
102
|
+
if (term_pointer[i-1].kind_of?(Hash))
|
103
|
+
#just use index supplied instead of trying possibilities
|
104
|
+
index = term_pointer[i-1].values.first
|
105
|
+
solr_name_base = OM::XML::Terminology.term_hierarchical_name({bases[j]=>index},current_last)
|
106
|
+
solr_name = generate_solr_symbol(solr_name_base, term.data_type)
|
107
|
+
bases.delete_at(j)
|
108
|
+
#insert the new solr name base if found
|
109
|
+
bases.insert(j,solr_name_base) if has_solr_name?(solr_name,solr_doc)
|
110
|
+
else
|
111
|
+
#detect how many nodes exist
|
112
|
+
index = 0
|
113
|
+
current_base = bases[j]
|
114
|
+
bases.delete_at(j)
|
115
|
+
solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
|
116
|
+
solr_name = generate_solr_symbol(solr_name_base, term.data_type)
|
117
|
+
bases.insert(j,solr_name_base)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
bases.each do |base|
|
122
|
+
names << generate_solr_symbol(base.to_sym, term.data_type)
|
123
|
+
end
|
124
|
+
else
|
125
|
+
#this is not hierarchical and we can simply look for the solr name created using the terms without any indexes
|
126
|
+
generic_field_name_base = OM::XML::Terminology.term_generic_name(*term_pointer)
|
127
|
+
names << generate_solr_symbol(generic_field_name_base, term.data_type)
|
128
|
+
end
|
129
|
+
names
|
130
|
+
end
|
131
|
+
|
132
|
+
# ** copied from ActiveFedora::NokogiriDatastream **
|
133
|
+
#@return true if the term_pointer contains an index
|
134
|
+
# ====Example:
|
135
|
+
# [:image, {:title_set=>1}, :title] return true
|
136
|
+
# [:image, :title_set, :title] return false
|
137
|
+
def is_hierarchical_term_pointer?(*term_pointer)
|
138
|
+
if term_pointer.length>1
|
139
|
+
term_pointer.each do |pointer|
|
140
|
+
if pointer.kind_of?(Hash)
|
141
|
+
return true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
return false
|
146
|
+
end
|
147
|
+
# ** copied from ActiveFedora::NokogiriDatastream **
|
148
|
+
def generate_solr_symbol(base, data_type)
|
149
|
+
Solrizer::XML::TerminologyBasedSolrizer.default_field_mapper.solr_name(base.to_sym, data_type)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'active-fedora'
|
2
|
+
module Cul
|
3
|
+
module Scv
|
4
|
+
module Hydra
|
5
|
+
module Om
|
6
|
+
class DCMetadata < ::ActiveFedora::NokogiriDatastream
|
7
|
+
include OM::XML::Document
|
8
|
+
after_save :action_after_save
|
9
|
+
set_terminology do |t|
|
10
|
+
t.root(:path=>"dc", :namespace_prefix=>"oai_dc",
|
11
|
+
"xmlns:oai_dc"=>"http://www.openarchives.org/OAI/2.0/oai_dc/",
|
12
|
+
"xmlns:dc"=>"http://purl.org/dc/elements/1.1/",
|
13
|
+
:schema=>"http://www.openarchives.org/OAI/2.0/oai_dc.xsd")
|
14
|
+
t.contributor(:path=>"contributor", :namespace_prefix=>"dc")
|
15
|
+
t.coverage(:path=>"coverage", :namespace_prefix=>"dc")
|
16
|
+
t.creator(:path=>"creator", :namespace_prefix=>"dc")
|
17
|
+
t.date(:path=>"date", :namespace_prefix=>"dc")
|
18
|
+
t.description(:path=>"description", :namespace_prefix=>"dc")
|
19
|
+
t.format(:path=>"format", :namespace_prefix=>"dc")
|
20
|
+
t.identifier(:path=>"identifier", :namespace_prefix=>"dc")
|
21
|
+
t.language(:path=>"language", :namespace_prefix=>"dc")
|
22
|
+
t.publisher(:path=>"publisher", :namespace_prefix=>"dc")
|
23
|
+
t.relation(:path=>"relation", :namespace_prefix=>"dc")
|
24
|
+
t.rights(:path=>"rights", :namespace_prefix=>"dc")
|
25
|
+
t.source(:path=>"source", :namespace_prefix=>"dc")
|
26
|
+
t.subject(:path=>"subject", :namespace_prefix=>"dc")
|
27
|
+
t.title(:path=>"title", :namespace_prefix=>"dc")
|
28
|
+
t.dc_type(:path=>"type", :namespace_prefix=>"dc")
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.xml_template
|
32
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
33
|
+
xml.dc(
|
34
|
+
"xmlns:oai_dc"=>"http://www.openarchives.org/OAI/2.0/oai_dc/",
|
35
|
+
"xmlns:dc"=>"http://purl.org/dc/elements/1.1/",
|
36
|
+
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance"){
|
37
|
+
xml.parent.namespace_definitions.each {|ns|
|
38
|
+
xml.parent.namespace = ns if ns.prefix == 'oai_dc'
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
builder.doc.encoding = 'UTF-8'
|
43
|
+
builder.doc.root["xsi:schemaLocation"] = 'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'
|
44
|
+
return builder.doc
|
45
|
+
end
|
46
|
+
def action_after_save
|
47
|
+
self.dirty= false
|
48
|
+
end
|
49
|
+
def method_missing method, *args
|
50
|
+
query = false
|
51
|
+
_mname = method.id2name
|
52
|
+
if _mname[-1,1] == '?'
|
53
|
+
query = true
|
54
|
+
_mname = _mname[0,_mname.length-1]
|
55
|
+
end
|
56
|
+
_msym = _mname.to_sym
|
57
|
+
has_term = self.class.terminology.has_term?(_msym)
|
58
|
+
return false if query and not has_term
|
59
|
+
_r = super(_mname.to_sym, *args)
|
60
|
+
if query
|
61
|
+
_r.length > 0
|
62
|
+
else
|
63
|
+
_r
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'active-fedora'
|
2
|
+
require 'solrizer'
|
3
|
+
require 'cul_scv_hydra/solrizer'
|
4
|
+
module Cul
|
5
|
+
module Scv
|
6
|
+
module Hydra
|
7
|
+
module Om
|
8
|
+
class ModsDocument < ::ActiveFedora::NokogiriDatastream
|
9
|
+
include OM::XML::Document
|
10
|
+
include Cul::Scv::Hydra::Solrizer::TerminologyBasedSolrizer
|
11
|
+
|
12
|
+
after_save :action_after_save
|
13
|
+
|
14
|
+
set_terminology do |t|
|
15
|
+
t.root(:path=>"mods",
|
16
|
+
:xmlns=>"http://www.loc.gov/mods/v3",
|
17
|
+
:schema=>"http://www.loc.gov/standards/mods/v3/mods-3-4.xsd")
|
18
|
+
|
19
|
+
t.main_title_info(:path=>'titleInfo', :index_as=>[:not_searchable], :attributes=>{:type=>:none}){
|
20
|
+
t.main_title(:path=>"title", :index_as=>[:displayable,:searchable])
|
21
|
+
}
|
22
|
+
|
23
|
+
t.search_title_info(:path=>'titleInfo', :index_as=>[:not_searchable]){
|
24
|
+
t.search_title(:path=>'title', :index_as=>[:searchable])
|
25
|
+
}
|
26
|
+
t.project(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Project"}, :index_as=>[:not_searchable]){
|
27
|
+
t.project_title_info(:path=>'titleInfo', :index_as=>[:not_searchable]){
|
28
|
+
t.lib_project(:path=>'title',:index_as=>[:displayable, :searchable])
|
29
|
+
t.lib_project_facet(:path=>'title', :index_as=>[:facetable, :not_searchable],:variant_of=>{:field_base=>'lib_project',:map=>:project_facet})
|
30
|
+
}
|
31
|
+
}
|
32
|
+
t.collection(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Collection"}, :index_as=>[:not_searchable]){
|
33
|
+
t.collection_title_info(:path=>'titleInfo', :index_as=>[:not_searchable]){
|
34
|
+
t.lib_collection(:path=>'title', :index_as=>[:facetable, :displayable])
|
35
|
+
}
|
36
|
+
}
|
37
|
+
t.title(:proxy=>[:mods,:main_title_info,:main_title], :index_as=>[:displayable,:searchable, :sortable])
|
38
|
+
t.lib_project(:proxy=>[:project,:project_title_info, :lib_project])
|
39
|
+
t.lib_collection(:proxy=>[:collection,:collection_title_info, :lib_collection])
|
40
|
+
# pattern matches
|
41
|
+
t.identifier(:path=>"identifier", :attributes=>{:type=>"local"}, :data_type=>:symbol)
|
42
|
+
t.identifier_text(:ref=>:identifier, :index_as=>[:not_searchable, :textable])
|
43
|
+
t.clio(:path=>"identifier", :attributes=>{:type=>"CLIO"}, :data_type=>:symbol)
|
44
|
+
t.abstract
|
45
|
+
t.subject {
|
46
|
+
t.topic
|
47
|
+
}
|
48
|
+
t.type_of_resource(:path=>"typeOfResource", :index_as=>[:not_searchable])
|
49
|
+
t.physical_description(:path=>"physicalDescription", :index_as=>[:not_searchable]){
|
50
|
+
t.form_marc(:path=>"form", :attributes=>{:authority=>"marcform"}, :index_as=>[:not_searchable])
|
51
|
+
t.form_aat(:path=>"form", :attributes=>{:authority=>"aat"}, :index_as=>[:not_searchable])
|
52
|
+
t.form(:attributes=>{:authority=>:none}, :index_as=>[:not_searchable])
|
53
|
+
t.form_nomarc(:path=>"form[@authority !='marcform']", :index_as=>[:not_searchable, :displayable, :facetable])
|
54
|
+
t.extent(:path=>"extent", :index_as=>[:not_searchable])
|
55
|
+
t.reformatting_quality(:path=>"reformattingQuality", :index_as=>[:not_searchable])
|
56
|
+
t.internet_media_type(:path=>"internetMediaType", :index_as=>[:not_searchable])
|
57
|
+
t.digital_origin(:path=>"digitalOrigin", :index_as=>[:not_searchable])
|
58
|
+
}
|
59
|
+
t.lib_format(:proxy=>[:physical_description, :form_nomarc])
|
60
|
+
t.location(:path=>"location", :index_as=>[:not_searchable]){
|
61
|
+
t.repo_text(:path=>"physicalLocation",:attributes=>{:authority=>:none}, :index_as=>[:not_searchable])
|
62
|
+
t.repo_code(:path=>"physicalLocation",:attributes=>{:authority=>"marcorg"}, :index_as=>[:not_searchable])
|
63
|
+
t.map_facet(:path=>"physicalLocation",:attributes=>{:authority=>"marcorg"}, :index_as=>[:facetable], :variant_of=>{:field_base=>'lib_repo',:map=>:marc_to_facet})
|
64
|
+
t.map_display(:path=>"physicalLocation",:attributes=>{:authority=>"marcorg"}, :index_as=>[:displayable, :not_searchable], :variant_of=>{:field_base=>'lib_repo',:map=>:marc_to_display})
|
65
|
+
t.shelf_locator(:path=>"shelfLocator", :index_as=>[:not_searchable, :textable])
|
66
|
+
}
|
67
|
+
t.name_personal(:path=>'name',:attributes=>{:type=>'personal'}, :index_as=>[:not_searchable]){
|
68
|
+
t.name_part(:path=>'namePart', :index_as=>[:facetable, :displayable, :searchable], :variant_of=>{:field_base=>:lib_name})
|
69
|
+
}
|
70
|
+
t.name_corporate(:path=>'name',:attributes=>{:type=>'corporate'}, :index_as=>[:not_searchable]){
|
71
|
+
t.name_part(:path=>'namePart', :index_as=>[:facetable, :displayable, :searchable], :variant_of=>{:field_base=>:lib_name})
|
72
|
+
}
|
73
|
+
t.note(:path=>"note", :index_as=>[:not_searchable, :textable])
|
74
|
+
t.access_condition(:path=>"accessCondition", :attributes=>{:type=>"useAndReproduction"}, :index_as => [:searchable], :data_type => :symbol)
|
75
|
+
t.record_info(:path=>"recordInfo", :index_as=>[:not_searchable]) {
|
76
|
+
t.record_creation_date(:path=>"recordCreationDate",:attributes=>{:encoding=>"w3cdtf"}, :index_as=>[:not_searchable])
|
77
|
+
t.record_content_source(:path=>"recordContentSource",:attributes=>{:authority=>"marcorg"}, :index_as=>[:not_searchable])
|
78
|
+
t.language_of_cataloging(:path=>"languageOfCataloging", :index_as=>[:not_searchable]){
|
79
|
+
t.language_term(:path=>"languageTerm", :index_as=>[:not_searchable], :attributes=>{:type=>:none})
|
80
|
+
t.language_code(:path=>"languageTerm",:attributes=>{:type=>'code',:authority=>"iso639-2b"}, :index_as=>[:not_searchable])
|
81
|
+
}
|
82
|
+
t.record_origin(:path=>"recordOrigin", :index_as=>[:not_searchable])
|
83
|
+
}
|
84
|
+
t.language_term(:proxy=>[:record_info, :language_of_cataloging, :language_term])
|
85
|
+
t.language_code(:proxy=>[:record_info, :language_of_cataloging, :language_code])
|
86
|
+
|
87
|
+
t.origin_info(:path=>"originInfo", :index_as=>[:not_searchable]){
|
88
|
+
t.date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf'}, :index_as=>[:not_searchable])
|
89
|
+
t.key_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes'}, :index_as=>[:not_searchable])
|
90
|
+
t.start_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes',:point=>'start'}, :index_as=>[:not_searchable])
|
91
|
+
t.end_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:point=>'end'}, :index_as=>[:not_searchable])
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.xml_template
|
96
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
97
|
+
xml.mods(:version=>"3.4",
|
98
|
+
"xmlns"=>"http://www.loc.gov/mods/v3",
|
99
|
+
"xmlns:xlink"=>"http://www.w3.org/1999/xlink",
|
100
|
+
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance"){
|
101
|
+
}
|
102
|
+
end
|
103
|
+
builder.doc.encoding = 'UTF-8'
|
104
|
+
# for some reason, this is the only way to get an equivalent nokogiri root node; the attribute can't be in the original builder call
|
105
|
+
builder.doc.root["xsi:schemaLocation"] = 'http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd'
|
106
|
+
return builder.doc
|
107
|
+
end
|
108
|
+
def action_after_save
|
109
|
+
self.dirty= false
|
110
|
+
end
|
111
|
+
def method_missing method, *args
|
112
|
+
query = false
|
113
|
+
_mname = method.id2name
|
114
|
+
if _mname[-1,1] == '?'
|
115
|
+
query = true
|
116
|
+
_mname = _mname[0,_mname.length-1]
|
117
|
+
end
|
118
|
+
_msym = _mname.to_sym
|
119
|
+
has_term = self.class.terminology.has_term?(_msym)
|
120
|
+
return false if query and not has_term
|
121
|
+
_r = super(_mname.to_sym, *args)
|
122
|
+
if query
|
123
|
+
_r.length > 0
|
124
|
+
else
|
125
|
+
_r
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'active-fedora'
|
2
|
+
require 'solrizer'
|
3
|
+
require 'cul_scv_hydra/solrizer'
|
4
|
+
module Cul
|
5
|
+
module Scv
|
6
|
+
module Hydra
|
7
|
+
module Om
|
8
|
+
class StandardMods
|
9
|
+
include OM::XML::Document
|
10
|
+
include ::Solrizer::XML::TerminologyBasedSolrizer
|
11
|
+
|
12
|
+
set_terminology do |t|
|
13
|
+
t.root(:path=>"mods",
|
14
|
+
:xmlns=>"http://www.loc.gov/mods/v3",
|
15
|
+
:schema=>"http://www.loc.gov/standards/mods/v3/mods-3-4.xsd")
|
16
|
+
t.identifier(:path=>"identifier", :attributes=>{:type=>"local"}, :data_type=>:symbol)
|
17
|
+
t.clio(:path=>"identifier", :attributes=>{:type=>"CLIO"}, :data_type=>:symbol)
|
18
|
+
t.title_info(:path=>"titleInfo", :index_as=>[:not_searchable]) {
|
19
|
+
t.main_title(:path=>"title", :index_as=>[:not_searchable])
|
20
|
+
}
|
21
|
+
t.title(:path=>'mods/oxns:titleInfo/oxns:title', :index_as=>[:searchable,:displayable, :sortable])
|
22
|
+
t.abstract
|
23
|
+
t.subject {
|
24
|
+
t.topic
|
25
|
+
}
|
26
|
+
t.type_of_resource(:path=>"typeOfResource", :index_as=>[:not_searchable])
|
27
|
+
t.physical_description(:path=>"physicalDescription", :index_as=>[:not_searchable]){
|
28
|
+
t.form_marc(:path=>"form", :attributes=>{:authority=>"marcform"}, :index_as=>[:not_searchable])
|
29
|
+
t.form_nomarc(:path=>"form[@authority !='marcform']", :index_as=>[:not_searchable, :displayable, :facetable])
|
30
|
+
t.extent(:path=>"extent", :index_as=>[:not_searchable])
|
31
|
+
t.reformatting_quality(:path=>"reformattingQuality", :index_as=>[:not_searchable])
|
32
|
+
t.internet_media_type(:path=>"internetMediaType", :index_as=>[:not_searchable])
|
33
|
+
t.digital_origin(:path=>"digitalOrigin", :index_as=>[:not_searchable])
|
34
|
+
}
|
35
|
+
t.lib_format(:proxy=>[:physical_description, :form_nomarc])
|
36
|
+
t.location(:path=>"location", :index_as=>[:not_searchable]){
|
37
|
+
t.repo_text(:path=>"physicalLocation",:attributes=>{:authority=>:none}, :index_as=>[:not_searchable])
|
38
|
+
t.repo_code(:path=>"physicalLocation",:attributes=>{:authority=>"marcorg"}, :index_as=>[:not_searchable])
|
39
|
+
}
|
40
|
+
t.lib_repo_text(:ref=>[:location, :repo_text], :label=>"lib_repo", :index_as=>[:searchable])
|
41
|
+
t.lib_repo(:ref=>[:location, :repo_code], :index_as=>[:not_searchable,:facetable, :displayable])
|
42
|
+
t.project_host(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Project"}, :index_as=>[:not_searchable]){
|
43
|
+
t.p_title(:path=>'titleInfo',:index_as=>[:not_searchable])
|
44
|
+
}
|
45
|
+
t.lib_project(:proxy=>[:project_host, :p_title],:index_as=>[:facetable,:displayable, :not_searchable])
|
46
|
+
t.collection_host(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Collection"}, :index_as=>[:not_searchable]){
|
47
|
+
t.c_title(:path=>'titleInfo',:index_as=>[:not_searchable])
|
48
|
+
}
|
49
|
+
t.lib_project(:path=>"mods/oxns:relatedItem[@type='host'][@displayLabel='Project']/oxns:titleInfo/oxns:title",:index_as=>[:facetable,:displayable, :not_searchable])
|
50
|
+
t.lib_collection(:path=>"mods/oxns:relatedItem[@type='host'][@displayLabel='Collection']/oxns:titleInfo/oxns:title",:index_as=>[:facetable,:displayable, :not_searchable])
|
51
|
+
t.note(:path=>"note")
|
52
|
+
t.access_condition(:path=>"accessCondition", :attributes=>{:type=>"useAndReproduction"}, :index_as => [:searchable], :data_type => :symbol)
|
53
|
+
t.record_info(:path=>"recordInfo", :index_as=>[:not_searchable]) {
|
54
|
+
t.record_creation_date(:path=>"recordCreationDate",:attributes=>{:encoding=>"w3cdtf"}, :index_as=>[:not_searchable])
|
55
|
+
t.record_content_source(:path=>"recordContentSource",:attributes=>{:authority=>"marcorg"}, :index_as=>[:not_searchable])
|
56
|
+
t.language_of_cataloging(:path=>"languageOfCataloging", :index_as=>[:not_searchable]){
|
57
|
+
t.language_term(:path=>"languageTerm", :index_as=>[:not_searchable], :attributes=>{:type=>:none})
|
58
|
+
t.language_code(:path=>"languageTerm",:attributes=>{:type=>'code',:authority=>"iso639-2b"}, :index_as=>[:not_searchable])
|
59
|
+
}
|
60
|
+
t.record_origin(:path=>"recordOrigin", :index_as=>[:not_searchable])
|
61
|
+
}
|
62
|
+
|
63
|
+
t.origin_info(:path=>"originInfo", :index_as=>[:not_searchable]){
|
64
|
+
t.date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf'}, :index_as=>[:not_searchable])
|
65
|
+
t.key_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes'}, :index_as=>[:not_searchable])
|
66
|
+
t.start_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes',:point=>'start'}, :index_as=>[:not_searchable])
|
67
|
+
t.end_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:point=>'end'}, :index_as=>[:not_searchable])
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.xml_template
|
72
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
73
|
+
xml.mods(:version=>"3.4",
|
74
|
+
"xmlns"=>"http://www.loc.gov/mods/v3",
|
75
|
+
"xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance"){
|
76
|
+
}
|
77
|
+
end
|
78
|
+
builder.doc.encoding = 'UTF-8'
|
79
|
+
builder.doc.root["xsi:schemaLocation"] = 'http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd'
|
80
|
+
return builder.doc
|
81
|
+
end
|
82
|
+
def method_missing method, *args
|
83
|
+
query = false
|
84
|
+
_mname = method.id2name
|
85
|
+
if _mname[-1,1] == '?'
|
86
|
+
query = true
|
87
|
+
_mname = _mname[0,_mname.length-1]
|
88
|
+
end
|
89
|
+
_msym = _mname.to_sym
|
90
|
+
begin
|
91
|
+
has_term = self.class.terminology.has_term?(_msym)
|
92
|
+
|
93
|
+
_r = (has_term)? find_by_terms(_msym, *args) : nil
|
94
|
+
if query
|
95
|
+
return !( _r.nil? || _r.size()==0)
|
96
|
+
else
|
97
|
+
return _r
|
98
|
+
end
|
99
|
+
rescue
|
100
|
+
super
|
101
|
+
end
|
102
|
+
end
|
103
|
+
def update_values(params)
|
104
|
+
super
|
105
|
+
self.dirty = true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|