cul_scv_hydra 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/app/models/bag_aggregator.rb +3 -2
  2. data/app/models/concerns/cul.rb +7 -0
  3. data/{lib/cul_scv_hydra/active_fedora.rb → app/models/concerns/cul/scv/hydra/models.rb} +4 -5
  4. data/{lib/cul_scv_hydra/active_fedora/model → app/models/concerns/cul/scv/hydra/models}/aggregator.rb +3 -3
  5. data/{lib/cul_scv_hydra/active_fedora/model → app/models/concerns/cul/scv/hydra/models}/common.rb +36 -9
  6. data/{lib/cul_scv_hydra/active_fedora/model → app/models/concerns/cul/scv/hydra/models}/resource.rb +2 -2
  7. data/app/models/content_aggregator.rb +3 -2
  8. data/app/models/cul/scv/hydra/datastreams/dc_metadata.rb +109 -0
  9. data/app/models/cul/scv/hydra/datastreams/mods_document.rb +157 -0
  10. data/{lib/cul_scv_hydra/active_fedora/model → app/models/cul/scv/hydra/datastreams}/struct_metadata.rb +10 -4
  11. data/app/models/dcdocument.rb +2 -1
  12. data/app/models/generic_aggregator.rb +4 -3
  13. data/app/models/generic_object.rb +3 -2
  14. data/app/models/generic_resource.rb +2 -1
  15. data/app/models/jp2_image_aggregator.rb +3 -2
  16. data/app/models/mets_structured_aggregator.rb +3 -2
  17. data/app/models/resource.rb +3 -2
  18. data/app/models/static_audio_aggregator.rb +3 -2
  19. data/app/models/static_image_aggregator.rb +3 -2
  20. data/bin/rails +12 -0
  21. data/lib/cul_scv_hydra.rb +0 -1
  22. data/lib/cul_scv_hydra/engine.rb +15 -0
  23. data/lib/cul_scv_hydra/om.rb +0 -2
  24. data/lib/cul_scv_hydra/om/standard_mods.rb +8 -0
  25. data/lib/cul_scv_hydra/version.rb +1 -1
  26. data/lib/tasks/cmodel.rake +11 -2
  27. metadata +29 -61
  28. data/lib/cul_scv_hydra/active_fedora/model.rb +0 -9
  29. data/lib/cul_scv_hydra/active_fedora/model/nokogiri_datastreams.rb +0 -142
  30. data/lib/cul_scv_hydra/om/dc_metadata.rb +0 -102
  31. data/lib/cul_scv_hydra/om/scv_mods_document.rb +0 -150
@@ -1,9 +0,0 @@
1
- module Cul::Scv::Hydra::ActiveFedora
2
- module Model
3
- end
4
- end
5
- require 'cul_scv_hydra/active_fedora/model/aggregator'
6
- require 'cul_scv_hydra/active_fedora/model/common'
7
- require 'cul_scv_hydra/active_fedora/model/resource'
8
- require 'cul_scv_hydra/active_fedora/model/nokogiri_datastreams'
9
- require 'cul_scv_hydra/active_fedora/model/struct_metadata'
@@ -1,142 +0,0 @@
1
- module Cul::Scv::Hydra::ActiveFedora::Model::NokogiriDatastreams
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- self.extend ClassMethods
6
- end
7
-
8
- module ClassMethods
9
- # Create an instance of this class based on xml content
10
- # @param [String, File, Nokogiri::XML::Node] xml the xml content to build from
11
- # @param [ActiveFedora::OmDatastream] tmpl the Datastream object that you are building @default a new instance of this class
12
- # Careful! If you call this from a constructor, be sure to provide something 'ie. self' as the @tmpl. Otherwise, you will get an infinite loop!
13
- def from_xml(xml, tmpl=nil)
14
- tmpl = self.new if tmpl.nil? ## This path is used only for unit testing (e.g. MarpaDCDatastream.from_xml(fixture("data.xml")) )
15
-
16
- if !xml.present?
17
- tmpl.ng_xml = self.xml_template
18
- elsif xml.kind_of? Nokogiri::XML::Node || xml.kind_of?(Nokogiri::XML::Document)
19
- tmpl.ng_xml = xml
20
- else
21
- tmpl.ng_xml = Nokogiri::XML::Document.parse(xml)
22
- end
23
-
24
- tmpl.ng_xml_doesnt_change!
25
-
26
- return tmpl
27
- end
28
- end
29
-
30
- def local_or_remote_content(ensure_fetch = true)
31
- @content = to_xml if ng_xml_changed? || autocreate?
32
- super
33
- end
34
-
35
- def datastream_content
36
- @datastream_content ||= Nokogiri::XML(super).to_xml {|config| config.no_declaration}.strip
37
- end
38
-
39
- def ng_xml
40
- @ng_xml ||= begin
41
- if new?
42
- ## Load up the template
43
- self.class.xml_template
44
- else
45
- Nokogiri::XML::Document.parse(datastream_content)
46
- end
47
- end
48
- end
49
-
50
- def ng_xml=(new_xml)
51
- # before we set ng_xml, we load the datastream so we know if the new value differs.
52
- local_or_remote_content(true)
53
-
54
- case new_xml
55
- when Nokogiri::XML::Document
56
- self.content=new_xml.to_xml
57
- when Nokogiri::XML::Node
58
- ## Cast a fragment to a document
59
- self.content=new_xml.to_s
60
- when String
61
- self.content=new_xml
62
- else
63
- raise TypeError, "You passed a #{new_xml.class} into the ng_xml of the #{self.dsid} datastream. OmDatastream.ng_xml= only accepts Nokogiri::XML::Document, Nokogiri::XML::Element, Nokogiri::XML::Node, or raw XML (String) as inputs."
64
- end
65
- end
66
-
67
- # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods
68
- def ng_xml_will_change!
69
- changed_attributes['ng_xml'] = nil
70
- end
71
-
72
- def ng_xml_doesnt_change!
73
- changed_attributes.delete('ng_xml')
74
- end
75
-
76
- # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods
77
- def ng_xml_changed?
78
- changed_attributes.has_key? 'ng_xml'
79
- end
80
-
81
- def datastream_content
82
- @datastream_content ||= Nokogiri::XML(super).to_xml {|config| config.no_declaration}.strip
83
- end
84
-
85
- def content=(new_content)
86
- if inline?
87
- # inline datastreams may be transformed by fedora 3, so we test for equivalence instead of equality
88
- if !EquivalentXml.equivalent?(datastream_content, new_content)
89
- ng_xml_will_change!
90
- @ng_xml = Nokogiri::XML::Document.parse(new_content)
91
- super(@ng_xml.to_s)
92
- end
93
- else
94
- if datastream_content != new_content
95
- ng_xml_will_change!
96
- @ng_xml = Nokogiri::XML::Document.parse(new_content)
97
- super(@ng_xml.to_s)
98
- end
99
- end
100
- end
101
-
102
- def content_changed?
103
- return false if !xml_loaded
104
- super
105
- end
106
-
107
- def xml_loaded
108
- instance_variable_defined? :@ng_xml
109
- end
110
-
111
- def to_xml(xml = nil)
112
- xml = self.ng_xml if xml.nil?
113
- ng_xml = self.ng_xml
114
- if ng_xml.respond_to?(:root) && ng_xml.root.nil? && self.class.respond_to?(:root_property_ref) && !self.class.root_property_ref.nil?
115
- ng_xml = self.class.generate(self.class.root_property_ref, "")
116
- if xml.root.nil?
117
- xml = ng_xml
118
- end
119
- end
120
-
121
- unless xml == ng_xml || ng_xml.root.nil?
122
- if xml.kind_of?(Nokogiri::XML::Document)
123
- xml.root.add_child(ng_xml.root)
124
- elsif xml.kind_of?(Nokogiri::XML::Node)
125
- xml.add_child(ng_xml.root)
126
- else
127
- raise "You can only pass instances of Nokogiri::XML::Node into this method. You passed in #{xml}"
128
- end
129
- end
130
-
131
- return xml.to_xml {|config| config.no_declaration}.strip
132
- end
133
-
134
- def method_missing method, *args, &block
135
- if ng_xml.respond_to? method
136
- ng_xml.send(method, *args, &block)
137
- else
138
- super
139
- end
140
- end
141
-
142
- end
@@ -1,102 +0,0 @@
1
- require 'active-fedora'
2
- module Cul
3
- module Scv
4
- module Hydra
5
- module Om
6
- class DCMetadata < ::ActiveFedora::OmDatastream
7
-
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.dc_contributor(:path=>"contributor",
15
- :namespace_prefix=>"dc",
16
- :index_as=>[:displayable, :searchable])
17
- t.dc_coverage(:path=>"coverage",
18
- :namespace_prefix=>"dc",
19
- :index_as=>[:displayable, :searchable])
20
- t.dc_creator(:path=>"creator",
21
- :namespace_prefix=>"dc",
22
- :index_as=>[:displayable, :searchable])
23
- t.dc_date(:path=>"date",
24
- :namespace_prefix=>"dc",
25
- :index_as=>[:displayable, :searchable])
26
- t.dc_description(:path=>"description",
27
- :namespace_prefix=>"dc",
28
- :index_as=>[:displayable, :searchable])
29
- t.dc_format(:path=>"format",
30
- :namespace_prefix=>"dc",
31
- :index_as=>[:displayable, :searchable])
32
- t.dc_identifier(:path=>"identifier",
33
- :namespace_prefix=>"dc",
34
- :type=>:string,
35
- :index_as=>[:symbol])
36
- t.dc_language(:path=>"language",
37
- :namespace_prefix=>"dc",
38
- :index_as=>[:displayable, :searchable])
39
- t.dc_publisher(:path=>"publisher",
40
- :namespace_prefix=>"dc",
41
- :index_as=>[:displayable, :searchable])
42
- t.dc_relation(:path=>"relation",
43
- :namespace_prefix=>"dc",
44
- :index_as=>[:displayable, :searchable])
45
- t.dc_rights(:path=>"rights",
46
- :namespace_prefix=>"dc",
47
- :index_as=>[:displayable, :searchable])
48
- t.dc_source(:path=>"source",
49
- :namespace_prefix=>"dc",
50
- :index_as=>[:displayable, :searchable])
51
- t.dc_subject(:path=>"subject",
52
- :namespace_prefix=>"dc",
53
- :index_as=>[:displayable, :searchable])
54
- t.dc_title(:path=>"title",
55
- :namespace_prefix=>"dc",
56
- :index_as=>[:displayable, :searchable])
57
- t.dc_type(:path=>"type",
58
- :namespace_prefix=>"dc",
59
- :index_as=>[:displayable, :searchable])
60
- end
61
-
62
- def self.xml_template
63
-
64
- Nokogiri::XML::Document.parse(<<-src
65
- <oai_dc:dc
66
- xmlns:oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/'
67
- xmlns:dc='http://purl.org/dc/elements/1.1/'
68
- xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
69
- xsi:schemaLocation='http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'></oai_dc:dc>
70
- src
71
- )
72
- end
73
- # Because FCRepo 3.5+ modifies DC on saves (to ensure that PID is a dc:identifier value),
74
- # this datastream's content must be reloaded after saves
75
- def action_after_save
76
- @content = nil
77
- @ng_xml = nil
78
- remove_instance_variable(:@ng_xml)
79
- end
80
-
81
- def method_missing method, *args
82
- query = false
83
- _mname = method.id2name
84
- if _mname[-1,1] == '?'
85
- query = true
86
- _mname = _mname[0,_mname.length-1]
87
- end
88
- _msym = _mname.to_sym
89
- has_term = self.class.terminology.has_term?(_msym)
90
- return false if query and not has_term
91
- _r = super(_mname.to_sym, *args)
92
- if query
93
- _r.length > 0
94
- else
95
- _r
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,150 +0,0 @@
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::OmDatastream
9
- include ::OM::XML::TerminologyBasedSolrizer
10
- include Cul::Scv::Hydra::Solrizer::TerminologyBasedSolrizer
11
- include Cul::Scv::Hydra::Solrizer::ScvModsFieldable
12
-
13
- map_field("lib_repo_sim", :marc_to_facet)
14
- map_field("lib_repo_ssm", :marc_to_display)
15
- map_field("lib_project_sim", :project_to_facet)
16
-
17
- set_terminology do |t|
18
- t.root(:path=>"mods",
19
- :xmlns=>"http://www.loc.gov/mods/v3",
20
- :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-4.xsd") {
21
- }
22
-
23
- t.main_title_info(:path=>'titleInfo', :index_as=>[], :attributes=>{:type=>:none}){
24
- t.non_sort(:path=>"nonSort", :index_as=>[])
25
- t.main_title(:path=>"title", :index_as=>[])
26
- }
27
-
28
- t.title(:proxy=>[:mods, :main_title_info, :main_title], :type=>:string,
29
- :index_as=>[:searchable, :sortable, :textable])
30
- t.title_display(:proxy=>[:mods, :main_title_info], :type=>:string,
31
- :index_as=>[:displayable])
32
-
33
- t.search_title_info(:path=>'titleInfo', :index_as=>[]){
34
- t.search_title(:path=>'title', :index_as=>[:searchable])
35
- }
36
- t.project(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Project"}, :index_as=>[]){
37
- t.project_title_info(:path=>'titleInfo', :index_as=>[]){
38
- t.lib_project(:path=>'title',:index_as=>[])
39
- }
40
- }
41
- t.collection(:path=>"relatedItem", :attributes=>{:type=>"host", :displayLabel=>"Collection"}, :index_as=>[]){
42
- t.collection_title_info(:path=>'titleInfo', :index_as=>[:facetable, :displayable]){
43
- t.lib_collection(:path=>'title', :index_as=>[])
44
- }
45
- }
46
- t.lib_project(:proxy=>[:project,:project_title_info],
47
- :index_as=>[:displayable, :searchable, :project_facetable, :textable])
48
- t.lib_collection(:proxy=>[:collection,:collection_title_info])
49
- # pattern matches
50
- t.identifier(:path=>"identifier", :attributes=>{:type=>"local"}, :type=>:string, :index_as=>[:symbol, :textable])
51
- t.clio(:path=>"identifier", :attributes=>{:type=>"CLIO"}, :data_type=>:symbol, :index_as=>[:symbol, :textable])
52
- t.abstract
53
- t.subject {
54
- t.topic
55
- }
56
- t.type_of_resource(:path=>"typeOfResource", :index_as=>[:displayable])
57
- t.physical_description(:path=>"physicalDescription", :index_as=>[]){
58
- t.form_marc(:path=>"form", :attributes=>{:authority=>"marcform"}, :index_as=>[:displayable])
59
- t.form_aat(:path=>"form", :attributes=>{:authority=>"aat"}, :index_as=>[:displayable])
60
- t.form(:attributes=>{:authority=>:none}, :index_as=>[:displayable])
61
- t.form_nomarc(:path=>"form[@authority !='marcform']", :index_as=>[])
62
- t.extent(:path=>"extent", :index_as=>[:searchable, :displayable])
63
- t.reformatting_quality(:path=>"reformattingQuality", :index_as=>[:displayable])
64
- t.internet_media_type(:path=>"internetMediaType", :index_as=>[:displayable])
65
- t.digital_origin(:path=>"digitalOrigin", :index_as=>[:displayable])
66
- }
67
- t.lib_format(:proxy=>[:physical_description, :form_nomarc], :index_as=>[:displayable, :facetable])
68
- t.location(:path=>"location", :index_as=>[]){
69
- t.repo_text(:path=>"physicalLocation",:attributes=>{:authority=>:none}, :index_as=>[])
70
- t.lib_repo(:path=>"physicalLocation",
71
- :attributes=>{:authority=>"marcorg"},
72
- :index_as=>[])
73
- t.shelf_locator(:path=>"shelfLocator", :index_as=>[:textable])
74
- }
75
- t.lib_repo(:proxy=>[:location, :lib_repo], :type=>:text,
76
- :index_as=>[:marc_code_facetable, :marc_code_displayable, :marc_code_textable])
77
- t.lib_name(
78
- :path=>'name',:attributes=>{:type=>'personal'},
79
- :index_as=>[:facetable, :displayable, :searchable, :textable]){
80
- t.name_part(:path=>'namePart', :index_as=>[])
81
- }
82
- t.name_corporate(
83
- :path=>'name',:attributes=>{:type=>'corporate'},
84
- :index_as=>[:facetable, :displayable, :searchable],
85
- :variant_of=>{:field_base=>:lib_name}){
86
- t.name_part(
87
- :path=>'namePart',
88
- :index_as=>[])
89
- }
90
- t.note(:path=>"note", :index_as=>[:textable])
91
- t.access_condition(:path=>"accessCondition",
92
- :attributes=>{:type=>"useAndReproduction"},
93
- :index_as => [:searchable, :symbol])
94
- t.record_info(:path=>"recordInfo", :index_as=>[]) {
95
- t.record_creation_date(:path=>"recordCreationDate",:attributes=>{:encoding=>"w3cdtf"}, :index_as=>[])
96
- t.record_content_source(:path=>"recordContentSource",:attributes=>{:authority=>"marcorg"}, :index_as=>[])
97
- t.language_of_cataloging(:path=>"languageOfCataloging", :index_as=>[]){
98
- t.language_term(:path=>"languageTerm", :index_as=>[], :attributes=>{:type=>:none})
99
- t.language_code(:path=>"languageTerm",:attributes=>{:type=>'code',:authority=>"iso639-2b"}, :index_as=>[])
100
- }
101
- t.record_origin(:path=>"recordOrigin", :index_as=>[])
102
- }
103
- t.language_term(:proxy=>[:record_info, :language_of_cataloging, :language_term])
104
- t.language_code(:proxy=>[:record_info, :language_of_cataloging, :language_code])
105
-
106
- t.origin_info(:path=>"originInfo", :index_as=>[]){
107
- t.date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf'}, :index_as=>[])
108
- t.lib_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes'},
109
- :index_as=>[:date_sortable])
110
- t.start_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:keyDate=>'yes',:point=>'start'}, :index_as=>[])
111
- t.end_date(:path=>"dateIssued", :attributes=>{:encoding=>'w3cdtf',:point=>'end'}, :index_as=>[])
112
- }
113
- end
114
-
115
- def self.xml_template
116
- builder = Nokogiri::XML::Builder.new do |xml|
117
- xml.mods(:version=>"3.4",
118
- "xmlns"=>"http://www.loc.gov/mods/v3",
119
- "xmlns:xlink"=>"http://www.w3.org/1999/xlink",
120
- "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance"){
121
- }
122
- end
123
- builder.doc.encoding = 'UTF-8'
124
- # 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
125
- builder.doc.root["xsi:schemaLocation"] = 'http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-4.xsd'
126
- return builder.doc
127
- end
128
-
129
- def method_missing method, *args
130
- query = false
131
- _mname = method.id2name
132
- if _mname[-1,1] == '?'
133
- query = true
134
- _mname = _mname[0,_mname.length-1]
135
- end
136
- _msym = _mname.to_sym
137
- has_term = self.class.terminology.has_term?(_msym)
138
- return false if query and not has_term
139
- _r = super(_mname.to_sym, *args)
140
- if query
141
- _r.length > 0
142
- else
143
- _r
144
- end
145
- end
146
- end
147
- end
148
- end
149
- end
150
- end