active-fedora 11.0.0.rc6 → 11.0.0.rc7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/active-fedora.gemspec +0 -3
  3. data/lib/active_fedora.rb +0 -10
  4. data/lib/active_fedora/associations/has_many_association.rb +1 -1
  5. data/lib/active_fedora/attributes.rb +1 -1
  6. data/lib/active_fedora/base.rb +3 -7
  7. data/lib/active_fedora/querying.rb +1 -1
  8. data/lib/active_fedora/rdf.rb +0 -1
  9. data/lib/active_fedora/version.rb +1 -1
  10. data/spec/integration/attached_files_spec.rb +14 -4
  11. data/spec/integration/file_spec.rb +22 -23
  12. data/spec/integration/versionable_spec.rb +0 -254
  13. data/spec/spec_helper.rb +0 -7
  14. data/spec/unit/attached_files_spec.rb +10 -7
  15. data/spec/unit/base_spec.rb +3 -1
  16. data/spec/unit/has_many_association_spec.rb +23 -8
  17. data/spec/unit/inheritance_spec.rb +11 -7
  18. data/spec/unit/model_classifier_spec.rb +1 -1
  19. data/spec/unit/rdf/indexing_service_spec.rb +9 -9
  20. data/spec/unit/solr_config_options_spec.rb +12 -15
  21. metadata +2 -67
  22. data/lib/active_fedora/datastreams.rb +0 -6
  23. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  24. data/lib/active_fedora/nom_datastream.rb +0 -73
  25. data/lib/active_fedora/om_datastream.rb +0 -118
  26. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  27. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
  28. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
  29. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -173
  30. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  31. data/spec/integration/complex_rdf_datastream_spec.rb +0 -227
  32. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -180
  33. data/spec/integration/ntriples_datastream_spec.rb +0 -215
  34. data/spec/integration/om_datastream_spec.rb +0 -78
  35. data/spec/samples/hydra-mods_article_datastream.rb +0 -515
  36. data/spec/samples/models/mods_article.rb +0 -9
  37. data/spec/samples/samples.rb +0 -2
  38. data/spec/unit/nom_datastream_spec.rb +0 -60
  39. data/spec/unit/ntriples_datastream_spec.rb +0 -167
  40. data/spec/unit/om_datastream_spec.rb +0 -294
  41. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  42. data/spec/unit/rdf_datastream_spec.rb +0 -84
  43. data/spec/unit/rdf_resource_datastream_spec.rb +0 -208
  44. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -1,73 +0,0 @@
1
- require "nom"
2
-
3
- module ActiveFedora
4
- class NomDatastream < File
5
- include Datastreams::NokogiriDatastreams
6
- extend Deprecation
7
-
8
- def self.set_terminology(options = {}, &block)
9
- @terminology_options = options || {}
10
- @terminology = block
11
- end
12
-
13
- def initialize(*args)
14
- super
15
- Deprecation.warn(NomDatastream, "NomDatastream is deprecated and will be removed in ActiveFedora 11")
16
- end
17
-
18
- class << self
19
- attr_reader :terminology_options
20
- end
21
-
22
- class << self
23
- attr_reader :terminology
24
- end
25
-
26
- def self.decorate_ng_xml(xml)
27
- xml.set_terminology terminology_options, &terminology
28
- xml.nom!
29
- xml
30
- end
31
-
32
- def serialize!
33
- self.content = @ng_xml.to_s if @ng_xml
34
- end
35
-
36
- def to_solr
37
- solr_doc = {}
38
-
39
- ng_xml.terminology.flatten.select { |x| x.options[:index] }.each do |term|
40
- term.values.each do |v|
41
- Array(term.options[:index]).each do |index_as|
42
- solr_doc[index_as] ||= []
43
- solr_doc[index_as] << if v.is_a? Nokogiri::XML::Node
44
- v.text
45
- else
46
- v
47
- end
48
- end
49
- end
50
- end
51
-
52
- solr_doc
53
- end
54
-
55
- def method_missing(method, *args, &block)
56
- if ng_xml.respond_to? method
57
- ng_xml.send(method, *args, &block)
58
- else
59
- super
60
- end
61
- end
62
-
63
- def respond_to?(*args)
64
- super || self.class.terminology.respond_to?(*args)
65
- end
66
-
67
- protected
68
-
69
- def default_mime_type
70
- 'text/xml'
71
- end
72
- end
73
- end
@@ -1,118 +0,0 @@
1
- require "om"
2
-
3
- module ActiveFedora
4
- class OmDatastream < File
5
- # before_save do
6
- # if content.blank?
7
- # ActiveFedora::Base.logger.warn "Cowardly refusing to save a datastream with empty content: #{self.inspect}"
8
- # false
9
- # end
10
- # end
11
-
12
- include OM::XML::Document
13
- include OM::XML::TerminologyBasedSolrizer # this adds support for calling .to_solr
14
- include Datastreams::NokogiriDatastreams
15
- extend Deprecation
16
-
17
- alias om_term_values term_values unless method_defined?(:om_term_values)
18
- alias om_update_values update_values unless method_defined?(:om_update_values)
19
-
20
- def initialize(*args)
21
- super
22
- Deprecation.warn(OmDatastream, "OmDatastream is deprecated and will be removed in ActiveFedora 11")
23
- end
24
-
25
- def default_mime_type
26
- 'text/xml'
27
- end
28
-
29
- # Indicates that this datastream has metadata content.
30
- # @return true
31
- def metadata?
32
- true
33
- end
34
-
35
- # Return a hash suitable for indexing in solr. Every field name is prefixed with the
36
- # value returned by the +prefix+ method.
37
- def to_solr(solr_doc = {}, opts = {})
38
- prefix = self.prefix(opts[:name])
39
- solr_doc.merge super({}).each_with_object({}) { |(key, value), new| new[[prefix, key].join] = value }
40
- end
41
-
42
- # Update field values within the current datastream using {#update_values}, which is a wrapper for {http://rdoc.info/gems/om/1.2.4/OM/XML/TermValueOperators#update_values-instance_method OM::TermValueOperators#update_values}
43
- # Ignores any fields from params that this datastream's Terminology doesn't recognize
44
- #
45
- # @param [Hash] params The params specifying which fields to update and their new values. The syntax of the params Hash is the same as that expected by
46
- # term_pointers must be a valid OM Term pointers (ie. [:name]). Strings will be ignored.
47
- # @param [Hash] _opts This is not currently used by the datastream-level update_indexed_attributes method
48
- #
49
- # Example:
50
- # @mods_ds.update_indexed_attributes( {[{":person"=>"0"}, "role"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} })
51
- # => {"person_0_role"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}}
52
- #
53
- # @mods_ds.to_xml # (the following is an approximation)
54
- # <mods>
55
- # <mods:name type="person">
56
- # <mods:role>
57
- # <mods:roleTerm>role1</mods:roleTerm>
58
- # </mods:role>
59
- # <mods:role>
60
- # <mods:roleTerm>role2</mods:roleTerm>
61
- # </mods:role>
62
- # <mods:role>
63
- # <mods:roleTerm>role3</mods:roleTerm>
64
- # </mods:role>
65
- # </mods:name>
66
- # </mods>
67
- def update_indexed_attributes(params = {}, _opts = {})
68
- if self.class.terminology.nil?
69
- raise "No terminology is set for this OmDatastream class. Cannot perform update_indexed_attributes"
70
- end
71
- # remove any fields from params that this datastream doesn't recognize
72
- # make sure to make a copy of params so not to modify hash that might be passed to other methods
73
- current_params = params.clone
74
- current_params.delete_if do |term_pointer, new_values|
75
- if term_pointer.is_a?(String)
76
- ActiveFedora::Base.logger.warn "WARNING: #{self.class.name} ignoring {#{term_pointer.inspect} => #{new_values.inspect}} because #{term_pointer.inspect} is a String (only valid OM Term Pointers will be used). Make sure your html has the correct field_selector tags in it." if ActiveFedora::Base.logger
77
- true
78
- else
79
- !self.class.terminology.has_term?(*OM.destringify(term_pointer))
80
- end
81
- end
82
-
83
- result = {}
84
- result = update_values(current_params) unless current_params.empty?
85
-
86
- result
87
- end
88
-
89
- def get_values(field_key, _default = [])
90
- term_values(*field_key)
91
- end
92
-
93
- def find_by_terms(*termpointer)
94
- super
95
- end
96
-
97
- # Update values in the datastream's xml
98
- # This wraps {http://rdoc.info/gems/om/1.2.4/OM/XML/TermValueOperators#update_values-instance_method OM::TermValueOperators#update_values} so that returns an error if we have loaded from solr since datastreams loaded that way should be read-only
99
- #
100
- # @example Updating multiple values with a Hash of Term pointers and values
101
- # ds.update_values( {[{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, [{:person=>1}, :family_name]=>"Andronicus", [{"person"=>"1"},:given_name]=>["Titus"],[{:person=>1},:role,:text]=>["otherrole1","otherrole2"] } )
102
- # => {"person_0_role_text"=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"}, "person_1_role_text"=>{"0"=>"otherrole1", "1"=>"otherrole2"}}
103
- def update_values(params = {})
104
- raise "can't modify frozen #{self.class}" if frozen?
105
- ng_xml_will_change!
106
- result = om_update_values(params)
107
- result
108
- end
109
-
110
- protected
111
-
112
- # The string to prefix all solr fields with. Override this method if you want
113
- # a prefix other than the default
114
- def prefix(path)
115
- path ? "#{path.underscore}__" : ''
116
- end
117
- end
118
- end
@@ -1,158 +0,0 @@
1
- module ActiveFedora
2
- # This class represents a Qualified Dublin Core Datastream. A special case of ActiveFedora::OmDatastream
3
- # The implementation of this class defines the terms from the Qualified Dublin Core specification.
4
- # This implementation features customized xml generators and deserialization routines to handle the
5
- # Fedora Dublin Core XML datastreams structure.
6
- #
7
- # Fields can still be overridden if more specificity is desired (see ActiveFedora::File#fields method).
8
- class QualifiedDublinCoreDatastream < OmDatastream
9
- attr_accessor :fields
10
- class_attribute :class_fields
11
- self.class_fields = []
12
-
13
- set_terminology do |t|
14
- t.root(path: "dc", xmlns: "http://purl.org/dc/terms/")
15
- end
16
-
17
- define_template :creator do |xml, name|
18
- xml.creator do
19
- xml.text(name)
20
- end
21
- end
22
-
23
- # A frozen array of Dublincore Terms.
24
- DCTERMS = [
25
- :abstract,
26
- :accessRights,
27
- :accrualMethod,
28
- :accrualPeriodicity,
29
- :accrualPolicy,
30
- :alternative,
31
- :audience,
32
- :available,
33
- :bibliographicCitation,
34
- :conformsTo,
35
- :contributor,
36
- :coverage,
37
- :created,
38
- :creator,
39
- :date,
40
- :dateAccepted,
41
- :dateCopyrighted,
42
- :dateSubmitted,
43
- :description,
44
- :educationLevel,
45
- :extent,
46
- :hasFormat,
47
- :hasPart,
48
- :hasVersion,
49
- :identifier,
50
- :instructionalMethod,
51
- :isFormatOf,
52
- :isPartOf,
53
- :isReferencedBy,
54
- :isReplacedBy,
55
- :isRequiredBy,
56
- :isVersionOf,
57
- :issued,
58
- :language,
59
- :license,
60
- :mediator,
61
- :medium,
62
- :modified,
63
- :provenance,
64
- :publisher,
65
- :references,
66
- :relation,
67
- :replaces,
68
- :requires,
69
- :rights,
70
- :rightsHolder,
71
- :source,
72
- :spatial,
73
- :subject,
74
- :tableOfContents,
75
- :temporal,
76
- :title,
77
- :type,
78
- :valid
79
- ].freeze # removed :format
80
- DCTERMS.freeze
81
-
82
- # Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
83
- # when this method returns. Each term is marked as a multivalue string.
84
- def initialize(string_or_url = nil)
85
- super
86
- self.fields = {}
87
- DCTERMS.each do |el|
88
- field el, :string, multiple: true
89
- end
90
- end
91
-
92
- # This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
93
- # each field will have the 2 magic methods:
94
- # name=(arg)
95
- # name
96
- #
97
- #
98
- # Calling any of the generated methods marks self as dirty.
99
- #
100
- # 'tupe' is a datatype, currently :string, :text and :date are supported.
101
- #
102
- # opts is an options hash, which will affect the generation of the xml representation of this datastream.
103
- #
104
- # Currently supported modifiers:
105
- # For +QualifiedDublinCorDatastreams+:
106
- # :element_attrs =>{:foo=>:bar} - hash of xml element attributes
107
- # :xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
108
- # :encoding=>foo, or encodings_scheme - causes an xsi:type attribute to be set to 'foo'
109
- # :multiple=>true - mark this field as a multivalue field (on by default)
110
- #
111
- #
112
- # There is quite a good example of this class in use in spec/examples/oral_history.rb
113
- #
114
- # !! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
115
- # you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
116
- # whenever you edit the field's values.
117
- def field(name, tupe = nil, opts = {})
118
- @fields[name.to_s.to_sym] = { type: tupe, values: [] }.merge(opts)
119
- # add term to template
120
- self.class.class_fields << name.to_s
121
- # add term to terminology
122
- return if self.class.terminology.has_term?(name.to_sym)
123
- om_term_opts = { xmlns: "http://purl.org/dc/terms/", namespace_prefix: "dcterms", path: opts[:path] }
124
- term = OM::XML::Term.new(name.to_sym, om_term_opts, self.class.terminology)
125
- self.class.terminology.add_term(term)
126
- term.generate_xpath_queries!
127
- end
128
-
129
- def update_indexed_attributes(params = {}, opts = {})
130
- # if the params are just keys, not an array, make then into an array.
131
- new_params = {}
132
- params.each do |key, val|
133
- if key.is_a? Array
134
- new_params[key] = val
135
- else
136
- new_params[[key.to_sym]] = val
137
- end
138
- end
139
- super(new_params, opts)
140
- end
141
-
142
- def self.xml_template
143
- Nokogiri::XML::Document.parse("<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>")
144
- end
145
-
146
- def to_solr(solr_doc = {}, _opts = {}) # :nodoc:
147
- @fields.each do |field_key, field_info|
148
- things = send(field_key)
149
- next unless things
150
- field_symbol = ActiveFedora.index_field_mapper.solr_name(field_key, type: field_info[:type])
151
- things.val.each do |val|
152
- ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val)
153
- end
154
- end
155
- solr_doc
156
- end
157
- end
158
- end
@@ -1,49 +0,0 @@
1
- module ActiveFedora::RDF
2
- module DatastreamIndexing
3
- extend ActiveSupport::Concern
4
-
5
- def to_solr(solr_doc = {}, opts = {}) # :nodoc:
6
- super.tap do |new_doc|
7
- solrize_rdf_assertions(opts[:name], new_doc)
8
- end
9
- end
10
-
11
- module ClassMethods
12
- def indexer
13
- ActiveFedora::RDF::IndexingService
14
- end
15
-
16
- def index_config
17
- @index_config ||= ActiveFedora::Indexing::Map.new
18
- end
19
- end
20
-
21
- protected
22
-
23
- def indexing_service
24
- @indexing_service ||= self.class.indexer.new(self)
25
- end
26
-
27
- # Serialize the datastream's RDF relationships to solr
28
- # @param [String] file_path used to prefix the keys in the solr document
29
- # @param [Hash] solr_doc @default an empty Hash
30
- def solrize_rdf_assertions(file_path, solr_doc = {})
31
- solr_doc.merge! indexing_service.generate_solr_document(prefix_method(file_path))
32
- end
33
-
34
- # Returns a function that takes field name and returns a solr document key
35
- def prefix_method(file_path)
36
- ->(field_name) { apply_prefix(field_name, file_path) }
37
- end
38
-
39
- def apply_prefix(name, file_path)
40
- prefix(file_path) + name.to_s
41
- end
42
-
43
- # The string to prefix all solr fields with. Override this method if you want
44
- # a prefix other than the default
45
- def prefix(path)
46
- path ? "#{path.underscore}__" : ''
47
- end
48
- end
49
- end
@@ -1,13 +0,0 @@
1
- require 'rdf/ntriples'
2
-
3
- module ActiveFedora
4
- class NtriplesRDFDatastream < RDFDatastream
5
- def serialization_format
6
- :ntriples
7
- end
8
-
9
- def deprecation_warning
10
- Deprecation.warn(NtriplesRDFDatastream, "NtriplesRDFDatastream is deprecated and will be removed in ActiveFedora 11", caller(2))
11
- end
12
- end
13
- end
@@ -1,173 +0,0 @@
1
- module ActiveFedora
2
- class RDFDatastream < File
3
- include ActiveTriples::NestedAttributes
4
- include RDF::DatastreamIndexing
5
- include ActiveTriples::Properties
6
- include ActiveTriples::Reflection
7
- extend Deprecation
8
-
9
- delegate :rdf_subject, :set_value, :get_values, :attributes=, to: :resource
10
- def initialize(*args)
11
- super
12
- deprecation_warning
13
- end
14
-
15
- def deprecation_warning
16
- Deprecation.warn(RDFDatastream, "RDFDatastream is deprecated and will be removed in ActiveFedora 11", caller(2))
17
- end
18
-
19
- class << self
20
- def rdf_subject(&block)
21
- return @subject_block = block if block_given?
22
-
23
- @subject_block ||= ->(ds) { parent_uri(ds) }
24
- end
25
-
26
- # Trim the last segment off the URI to get the parents uri
27
- def parent_uri(ds)
28
- m = /^(.*)\/[^\/]*$/.match(ds.uri)
29
- if m
30
- m[1]
31
- else
32
- ::RDF::URI.new(nil)
33
- end
34
- end
35
-
36
- ##
37
- # @param [Class] klass an object to set as the resource class, Must be a descendant of
38
- # ActiveTriples::Resource and include ActiveFedora::RDF::Persistence.
39
- #
40
- # @return [Class] the object resource class
41
- def resource_class(klass = nil)
42
- if klass
43
- raise ArgumentError, "#{self} already has a resource_class #{@resource_class}, cannot redefine it to #{klass}" if @resource_class && klass != @resource_class
44
- raise ArgumentError, "#{klass} must be a subclass of ActiveTriples::Resource" unless klass < ActiveTriples::Resource
45
- end
46
-
47
- @resource_class ||= begin
48
- klass = Class.new(klass || ActiveTriples::Resource)
49
- klass.send(:include, RDF::Persistence)
50
- klass
51
- end
52
- end
53
- end
54
-
55
- before_save do
56
- if content.blank?
57
- ActiveFedora::Base.logger.warn "Cowardly refusing to save a datastream with empty content: #{inspect}" if ActiveFedora::Base.logger
58
- if ActiveSupport.respond_to?(:halt_callback_chains_on_return_false)
59
- # For Rails 5+
60
- throw :abort
61
- else
62
- # For Rails <= 4
63
- false
64
- end
65
- end
66
- end
67
-
68
- def parent_uri
69
- self.class.parent_uri(self)
70
- end
71
-
72
- def metadata?
73
- true
74
- end
75
-
76
- def content
77
- serialize
78
- end
79
-
80
- def content=(new_content)
81
- resource.clear!
82
- resource << deserialize(new_content)
83
- content
84
- end
85
-
86
- def uri=(uri)
87
- super
88
- resource.set_subject!(parent_uri) if empty_or_blank_subject?
89
- end
90
-
91
- def content_changed?
92
- return false unless instance_variable_defined? :@resource
93
- return true if empty_or_blank_subject? # can't be serialized because a subject hasn't been assigned yet.
94
- @content = serialize
95
- super
96
- end
97
-
98
- def empty_or_blank_subject?
99
- resource.rdf_subject.node? || resource.rdf_subject.value.blank?
100
- end
101
-
102
- def freeze
103
- @resource.freeze
104
- end
105
-
106
- ##
107
- # The resource is the RdfResource object that stores the graph for
108
- # the datastream and is the central point for its relationship to
109
- # other nodes.
110
- #
111
- # set_value, get_value, and property accessors are delegated to this object.
112
- def resource
113
- @resource ||= begin
114
- klass = self.class.resource_class
115
- klass.properties.merge(self.class.properties).each do |_prop, config|
116
- klass.property(config.term,
117
- predicate: config.predicate,
118
- class_name: config.class_name)
119
- end
120
- klass.accepts_nested_attributes_for(*nested_attributes_options.keys) unless nested_attributes_options.blank?
121
- uri_stub = self.class.rdf_subject.call(self)
122
-
123
- r = klass.new(uri_stub)
124
- r.datastream = self
125
- r << deserialize
126
- r
127
- end
128
- end
129
-
130
- alias graph resource
131
-
132
- def refresh_attributes
133
- @resource = nil
134
- end
135
-
136
- ##
137
- # This method allows for delegation.
138
- # This patches the fact that there's no consistent API for allowing delegation - we're matching the
139
- # OmDatastream implementation as our "consistency" point.
140
- # @TODO: We may need to enable deep RDF delegation at one point.
141
- def term_values(*values)
142
- send(values.first)
143
- end
144
-
145
- def update_indexed_attributes(hash)
146
- hash.each do |fields, value|
147
- fields.each do |field|
148
- send("#{field}=", value)
149
- end
150
- end
151
- end
152
-
153
- def serialize
154
- resource.set_subject!(parent_uri) if parent_uri && rdf_subject.node?
155
- resource.dump serialization_format
156
- end
157
-
158
- def deserialize(data = nil)
159
- return ::RDF::Graph.new if new_record? && data.nil?
160
- data ||= remote_content
161
-
162
- # Because datastream_content can return nil, we should check that here.
163
- return ::RDF::Graph.new if data.nil?
164
-
165
- data.force_encoding('utf-8')
166
- ::RDF::Graph.new << ::RDF::Reader.for(serialization_format).new(data)
167
- end
168
-
169
- def serialization_format
170
- raise "you must override the `serialization_format' method in a subclass"
171
- end
172
- end
173
- end