active-fedora 4.2.0 → 4.3.0

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.
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active-fedora (4.2.0)
4
+ active-fedora (4.3.0)
5
5
  activeresource (>= 3.0.0)
6
6
  activesupport (>= 3.0.0)
7
7
  equivalent-xml
8
8
  mediashelf-loggable
9
9
  mime-types (>= 1.16)
10
- multipart-post (= 1.1.2)
10
+ multipart-post
11
11
  nokogiri
12
12
  om (~> 1.6.0)
13
13
  rdf
@@ -31,9 +31,10 @@ GEM
31
31
  i18n (~> 0.6)
32
32
  multi_json (~> 1.0)
33
33
  addressable (2.2.8)
34
- akami (1.0.0)
34
+ akami (1.1.0)
35
35
  gyoku (>= 0.4.0)
36
- backports (2.5.3)
36
+ nokogiri (>= 1.5.2)
37
+ backports (2.6.1)
37
38
  builder (3.0.0)
38
39
  childprocess (0.3.2)
39
40
  ffi (~> 1.0.6)
@@ -46,7 +47,7 @@ GEM
46
47
  ffi (1.0.11)
47
48
  gyoku (0.4.5)
48
49
  builder (>= 2.1.2)
49
- httpi (0.9.7)
50
+ httpi (1.0.0)
50
51
  rack
51
52
  i18n (0.6.0)
52
53
  jettywrapper (1.2.1)
@@ -65,7 +66,7 @@ GEM
65
66
  metaclass (~> 0.0.1)
66
67
  multi_json (1.3.5)
67
68
  multipart-post (1.1.2)
68
- nokogiri (1.5.2)
69
+ nokogiri (1.5.3)
69
70
  nori (1.1.0)
70
71
  om (1.6.0)
71
72
  mediashelf-loggable
@@ -108,14 +109,14 @@ GEM
108
109
  nokogiri
109
110
  rest-client
110
111
  savon
111
- savon (0.9.9)
112
- akami (~> 1.0)
112
+ savon (0.9.14)
113
+ akami (~> 1.1)
113
114
  builder (>= 2.1.2)
114
115
  gyoku (>= 0.4.0)
115
- httpi (~> 0.9)
116
+ httpi (~> 1.0)
116
117
  nokogiri (>= 1.4.0)
117
118
  nori (~> 1.1)
118
- wasabi (~> 2.1)
119
+ wasabi (~> 2.2)
119
120
  simplecov (0.6.4)
120
121
  multi_json (~> 1.0)
121
122
  simplecov-html (~> 0.5.3)
@@ -130,7 +131,7 @@ GEM
130
131
  stomp
131
132
  xml-simple
132
133
  stomp (1.2.2)
133
- wasabi (2.1.1)
134
+ wasabi (2.3.0)
134
135
  nokogiri (>= 1.4.0)
135
136
  xml-simple (1.1.1)
136
137
  yard (0.8.1)
@@ -1,3 +1,9 @@
1
+ 4.3.0
2
+ Added the #delegate_to method for easier delegation of multiple terms to the same datastream.
3
+ Deprecated AF::Base#file_streams
4
+ Deprecated AF::Base#to_xml
5
+ HYDRA-826 Added SimpleDatastream as a replacement for MetadataDatastream
6
+
1
7
  4.2.0
2
8
  Added Base.find_each which allows yielding of each result
3
9
  Added Base.find_in_batches which allows yielding of a chunk of solr results
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency('rsolr')
19
19
  s.add_dependency('xml-simple', '>= 1.0.12')
20
20
  s.add_dependency('mime-types', '>= 1.16')
21
- s.add_dependency('multipart-post', "= 1.1.2")
21
+ s.add_dependency('multipart-post')
22
22
  s.add_dependency('nokogiri')
23
23
  s.add_dependency('om', '~> 1.6.0')
24
24
  s.add_dependency('solrizer', '~>1.2.0')
@@ -51,6 +51,7 @@ module ActiveFedora #:nodoc:
51
51
  autoload :RelsExtDatastream
52
52
  autoload :ServiceDefinitions
53
53
  autoload :SemanticNode
54
+ autoload :SimpleDatastream
54
55
  autoload :NestedAttributes
55
56
  autoload :FixtureLoader
56
57
  autoload :FixtureExporter
@@ -30,21 +30,16 @@ module ActiveFedora
30
30
  self.profile_solr_name = ActiveFedora::SolrService.solr_name("object_profile", :string, :displayable)
31
31
 
32
32
  def method_missing(name, *args)
33
- # if [:collection_members, :part_of, :parts, :part_of_append, :file_objects].include? name
34
- # ActiveSupport::Deprecation.warn("Deprecation: FileManagement will not be included by default in the next version. To use #{name} add 'include ActiveFedora::FileManagement' to your model")
35
- # self.class.send :include, FileManagement
36
- # send name, *args
37
- # else
38
- dsid = corresponding_datastream_name(name)
39
- if dsid
40
- ### Create and invoke a proxy method
41
- self.class.send :define_method, name do
42
- datastreams[dsid]
43
- end
44
- self.send(name)
45
- else
46
- super
33
+ dsid = corresponding_datastream_name(name)
34
+ if dsid
35
+ ### Create and invoke a proxy method
36
+ self.class.send :define_method, name do
37
+ datastreams[dsid]
47
38
  end
39
+ self.send(name)
40
+ else
41
+ super
42
+ end
48
43
  end
49
44
 
50
45
 
@@ -54,7 +49,7 @@ module ActiveFedora
54
49
  end
55
50
 
56
51
  def new_object=(bool)
57
- ActiveSupport::Deprecation.warn("ActiveFedora::Base.new_object= has been deprecated and nolonger has any effect")
52
+ ActiveSupport::Deprecation.warn("ActiveFedora::Base.new_object= has been deprecated and nolonger has any effect. Will be removed in 5.0")
58
53
  end
59
54
 
60
55
  ## Required by associations
@@ -263,13 +258,14 @@ module ActiveFedora
263
258
  # TODO this can likely be removed once find_by_fields_by_solr is removed
264
259
  fields = {:id => {:values => [pid]}, :system_create_date => {:values => [self.create_date], :type=>:date}, :system_modified_date => {:values => [self.modified_date], :type=>:date}, :active_fedora_model => {:values => [self.class.inspect], :type=>:symbol}}
265
260
  datastreams.values.each do |ds|
266
- fields.merge!(ds.fields) if [ActiveFedora::MetadataDatastream, ActiveFedora::QualifiedDublinCoreDatastream].include?(ds.class)
261
+ fields.merge!(ds.fields) if [ActiveFedora::MetadataDatastream, ActiveFedora::SimpleDatastream, ActiveFedora::QualifiedDublinCoreDatastream].include?(ds.class)
267
262
  end
268
263
  return fields
269
264
  end
270
265
 
271
266
  #Returns the xml version of this object as a string.
272
267
  def to_xml(xml=Nokogiri::XML::Document.parse("<xml><fields/><content/></xml>"))
268
+ ActiveSupport::Deprecation.warn("ActiveFedora::Base#to_xml has been deprecated and will be removed in version 5.0")
273
269
  fields_xml = xml.xpath('//fields').first
274
270
  builder = Nokogiri::XML::Builder.with(fields_xml) do |fields_xml|
275
271
  fields_xml.id_ pid
@@ -278,12 +274,6 @@ module ActiveFedora
278
274
  fields_xml.active_fedora_model self.class.inspect
279
275
  end
280
276
 
281
- # {:id => pid, :system_create_date => self.create_date, :system_modified_date => self.modified_date, :active_fedora_model => self.class.inspect}.each_pair do |attribute_name, value|
282
- # el = REXML::Element.new(attribute_name.to_s)
283
- # el.text = value
284
- # fields_xml << el
285
- # end
286
-
287
277
  datastreams.each_value do |ds|
288
278
  ds.to_xml(fields_xml) if ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper)
289
279
  ds.to_rels_ext if ds.kind_of?(ActiveFedora::RelsExtDatastream)
@@ -317,7 +307,6 @@ module ActiveFedora
317
307
  end
318
308
  datastreams.each_value do |ds|
319
309
  ds.ensure_xml_loaded if ds.respond_to? :ensure_xml_loaded ### Can't put this in the model because it's often implemented in Solrizer::XML::TerminologyBasedSolrizer
320
- #puts "\n\nQDC #{ds.to_solr(solr_doc).inspect}" if ds.kind_of?(ActiveFedora::QualifiedDublinCoreDatastream)
321
310
  solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::RDFDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ds.kind_of?(ActiveFedora::MetadataDatastream)
322
311
  end
323
312
  solr_doc = solrize_relationships(solr_doc) unless opts[:model_only]
@@ -113,7 +113,7 @@ module ActiveFedora
113
113
  end
114
114
 
115
115
  def add(datastream) # :nodoc:
116
- warn "Warning: ActiveFedora::Base.add has been deprecated. Use add_datastream"
116
+ ActiveSupport::Deprecation.warn "Warning: ActiveFedora::Base.add has been deprecatedand will be removed in 5.0. Use add_datastream"
117
117
  add_datastream(datastream)
118
118
  end
119
119
 
@@ -130,10 +130,12 @@ module ActiveFedora
130
130
 
131
131
  #return all datastreams not of type ActiveFedora::MetadataDatastream
132
132
  #(that aren't Dublin Core or RELS-EXT streams either)
133
+ #@deprecated
133
134
  def file_streams
135
+ ActiveSupport::Deprecation.warn("ActiveFedora::Base#file_streams has been deprecated and will be removed in 5.0")
134
136
  results = []
135
137
  datastreams.each_value do |ds|
136
- if !ds.kind_of?(ActiveFedora::MetadataDatastream)
138
+ if !ds.kind_of?(ActiveFedora::MetadataDatastream) && !ds.kind_of?(ActiveFedora::NokogiriDatastream)
137
139
  dsid = ds.dsid
138
140
  if dsid != "DC" && dsid != "RELS-EXT"
139
141
  results << ds
@@ -1,18 +1,18 @@
1
1
  module ActiveFedora
2
2
  module Delegating
3
3
  extend ActiveSupport::Concern
4
-
4
+
5
5
  module ClassMethods
6
6
  # Provides a delegate class method to expose methods in metadata streams
7
- # as member of the base object. Pass the target datastream via the
8
- # <tt>:to</tt> argument. If you want to return a unique result, (e.g. string
7
+ # as member of the base object. Pass the target datastream via the
8
+ # <tt>:to</tt> argument. If you want to return a unique result, (e.g. string
9
9
  # instead of an array) set the <tt>:unique</tt> argument to true.
10
10
  #
11
11
  # The optional <tt>:at</tt> argument provides a terminology that the delegate will point to.
12
- #
12
+ #
13
13
  # class Foo < ActiveFedora::Base
14
- # has_metadata :name => "descMetadata", :type => MyDatastream
15
- #
14
+ # has_metadata :name => "descMetadata", :type => MyDatastream
15
+ #
16
16
  # delegate :field1, :to=>"descMetadata", :unique=>true
17
17
  # delegate :field2, :to=>"descMetadata", :at=>[:term1, :term2]
18
18
  # end
@@ -26,27 +26,54 @@ module ActiveFedora
26
26
  create_delegate_accessor(field, args)
27
27
  create_delegate_setter(field, args)
28
28
  end
29
-
29
+
30
+
31
+ # Allows you to delegate multiple terminologies to the same datastream, instead
32
+ # having to call the method each time for each term. The target datastream is the
33
+ # first argument, followed by an array of the terms that will point to that
34
+ # datastream. Terms must be a single value, ie. :field and not [:term1, :term2].
35
+ # This is best accomplished by refining your OM terminology using :ref or :proxy
36
+ # methods to reduce nested terms down to one.
37
+ #
38
+ # class Foo < ActiveFedora::Base
39
+ # has_metadata :name => "descMetadata", :type => MyDatastream
40
+ #
41
+ # delegate_to :descMetadata, [:field1, :field2]
42
+ # end
43
+ #
44
+ # foo = Foo.new
45
+ # foo.field1 = "My Value"
46
+ # foo.field1 # => "My Value"
47
+ # foo.field2 # => NoMethodError: undefined method `field2' for #<Foo:0x1af30c>
48
+
49
+ def delegate_to(datastream,fields,args={})
50
+ fields.each do |f|
51
+ args.merge!({:to=>datastream})
52
+ create_delegate_accessor(f, args)
53
+ create_delegate_setter(f, args)
54
+ end
55
+ end
56
+
30
57
  private
31
58
  def create_delegate_accessor(field, args)
32
59
  define_method field do
33
60
  ds = self.send(args[:to])
34
61
  val = if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::RDFDatastream)
35
62
  ds.send(:get_values, field)
36
- else
63
+ else
37
64
  terminology = args[:at] || [field]
38
65
  ds.send(:term_values, *terminology)
39
66
  end
40
67
  args[:unique] ? val.first : val
41
68
  end
42
69
  end
43
-
70
+
44
71
  def create_delegate_setter(field, args)
45
72
  define_method "#{field}=".to_sym do |v|
46
73
  ds = self.send(args[:to])
47
74
  if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::RDFDatastream)
48
75
  ds.send(:set_value, field, v)
49
- else
76
+ else
50
77
  terminology = args[:at] || [field]
51
78
  ds.send(:update_indexed_attributes, {terminology => v})
52
79
  end
@@ -97,7 +97,7 @@ module ActiveFedora
97
97
  # Returns an Array of objects of the Class that +find+ is being
98
98
  # called on
99
99
  #
100
- # @param[String,Symbol, Hash] either a pid or :all or a hash of conditions
100
+ # @param[String,Symbol,Hash] args either a pid or :all or a hash of conditions
101
101
  # @param [Hash] opts the options to create a message with.
102
102
  # @option opts [Integer] :rows when :all is passed, the maximum number of rows to load from solr
103
103
  # @option opts [Boolean] :cast when true, examine the model and cast it to the first known cModel
@@ -0,0 +1,92 @@
1
+ module ActiveFedora
2
+ #This class represents a simple xml datastream.
3
+ class SimpleDatastream < NokogiriDatastream
4
+
5
+ class_attribute :class_fields
6
+ self.class_fields = []
7
+ attr_accessor :fields # TODO this can be removed when Model.find_by_fields_by_solr has been removed.
8
+
9
+
10
+ set_terminology do |t|
11
+ t.root(:path=>"fields", :xmlns=>nil)
12
+ end
13
+
14
+ define_template :creator do |xml,name|
15
+ xml.creator() do
16
+ xml.text(name)
17
+ end
18
+ end
19
+
20
+
21
+ # This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
22
+ # each field will have the 2 magic methods:
23
+ # name=(arg)
24
+ # name
25
+ #
26
+ #
27
+ # 'datatype' is a datatype, currently :string, :text and :date are supported.
28
+ #
29
+ # opts is an options hash, which will affect the generation of the xml representation of this datastream.
30
+ #
31
+ # Currently supported modifiers:
32
+ # For +QualifiedDublinCorDatastreams+:
33
+ # :element_attrs =>{:foo=>:bar} - hash of xml element attributes
34
+ # :xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
35
+ # :encoding=>foo, or encodings_scheme - causes an xsi:type attribute to be set to 'foo'
36
+ # :multiple=>true - mark this field as a multivalue field (on by default)
37
+ #
38
+ #At some point, these modifiers will be ported up to work for any +ActiveFedora::MetadataDatastream+.
39
+ #
40
+ #There is quite a good example of this class in use in spec/examples/oral_history.rb
41
+ #
42
+ #!! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
43
+ #you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
44
+ #whenever you edit the field's values.
45
+ def field(name, datatype=nil, opts={})
46
+ fields ||= {}
47
+ @fields[name.to_s.to_sym]={:type=>datatype, :values=>[]}.merge(opts)
48
+ # add term to template
49
+ self.class.class_fields << name.to_s
50
+ # add term to terminology
51
+ unless self.class.terminology.has_term?(name.to_sym)
52
+ term = OM::XML::Term.new(name.to_sym, {}, self.class.terminology)
53
+ self.class.terminology.add_term(term)
54
+ term.generate_xpath_queries!
55
+ end
56
+
57
+ end
58
+
59
+ def update_indexed_attributes(params={}, opts={})
60
+ # if the params are just keys, not an array, make then into an array.
61
+ new_params = {}
62
+ params.each do |key, val|
63
+ if key.is_a? Array
64
+ new_params[key] = val
65
+ else
66
+ new_params[[key.to_sym]] = val
67
+ end
68
+ end
69
+ super(new_params, opts)
70
+ end
71
+
72
+
73
+ def self.xml_template
74
+ Nokogiri::XML::Document.parse("<fields/>")
75
+ end
76
+
77
+ def to_solr(solr_doc = Hash.new) # :nodoc:
78
+ @fields.each do |field_key, field_info|
79
+ next if field_key == :location ## FIXME HYDRA-825
80
+ things = send(field_key)
81
+ if things
82
+ field_symbol = ActiveFedora::SolrService.solr_name(field_key, field_info[:type])
83
+ things.val.each do |val|
84
+ ::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val )
85
+ end
86
+ end
87
+ end
88
+ return solr_doc
89
+ end
90
+
91
+ end
92
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "4.2.0"
2
+ VERSION = "4.3.0"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class MockAFBaseQuerySolr < ActiveFedora::Base
4
- has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
4
+ has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream do |m|
5
5
  m.field "holding_id", :string
6
6
  end
7
7
 
@@ -136,7 +136,7 @@ describe ActiveFedora::Base do
136
136
  has_relationship "testing_inbound", :has_part, :type=>MockAFBaseFromSolr, :inbound=>true
137
137
  has_relationship "testing_inbound2", :has_member, :type=>MockAFBaseFromSolr, :inbound=>true
138
138
 
139
- has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
139
+ has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream do |m|
140
140
  m.field "holding_id", :string
141
141
  end
142
142
 
@@ -266,8 +266,8 @@ describe ActiveFedora::Base do
266
266
  end
267
267
 
268
268
  describe ".metadata_streams" do
269
- it "should return all of the datastreams from the object that are kinds of MetadataDatastreams " do
270
- mds1 = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, "md1")
269
+ it "should return all of the datastreams from the object that are kinds of NokogiriDatastream " do
270
+ mds1 = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, "md1")
271
271
  mds2 = ActiveFedora::QualifiedDublinCoreDatastream.new(@test_object.inner_object, "qdc")
272
272
  fds = ActiveFedora::Datastream.new(@test_object.inner_object, "fds")
273
273
  @test_object.add_datastream(mds1)
@@ -282,10 +282,10 @@ describe ActiveFedora::Base do
282
282
  end
283
283
 
284
284
  describe ".file_streams" do
285
- it "should return all of the datastreams from the object that are kinds of MetadataDatastreams" do
285
+ it "should return all of the datastreams from the object that are kinds of NokogiriDatastream" do
286
286
  fds1 = ActiveFedora::Datastream.new(@test_object.inner_object, "fds1")
287
287
  fds2 = ActiveFedora::Datastream.new(@test_object.inner_object, "fds2")
288
- mds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, "mds")
288
+ mds = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, "mds")
289
289
  @test_object.add_datastream(fds1)
290
290
  @test_object.add_datastream(fds2)
291
291
  @test_object.add_datastream(mds)
@@ -11,11 +11,11 @@ include Mocha::API
11
11
  describe 'bugs' do
12
12
  before :all do
13
13
  class FooHistory < ActiveFedora::Base
14
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"someData" do |m|
14
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"someData" do |m|
15
15
  m.field "fubar", :string
16
16
  m.field "swank", :text
17
17
  end
18
- has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"withText" do |m|
18
+ has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText" do |m|
19
19
  m.field "fubar", :text
20
20
  end
21
21
  end
@@ -33,22 +33,22 @@ describe 'bugs' do
33
33
  end
34
34
  it "should not clobber everything when setting a value" do
35
35
  ds = @test_object.datastreams["someData"]
36
- ds.fubar_values.should == []
36
+ ds.fubar.should == []
37
37
  ds.should_not be_nil
38
- ds.fubar_values=['bar']
39
- ds.fubar_values.should == ['bar']
38
+ ds.fubar=['bar']
39
+ ds.fubar.should == ['bar']
40
40
  @test_object.save
41
41
 
42
42
  @test_object.pid.should_not be_nil
43
43
 
44
44
  x = FooHistory.find(@test_object.pid)
45
45
  ds2 = x.datastreams["someData"]
46
- ds2.fubar_values.should == ['bar']
47
- ds2.fubar_values = ["meh"]
48
- ds2.fubar_values.should == ["meh"]
46
+ ds2.fubar.should == ['bar']
47
+ ds2.fubar = ["meh"]
48
+ ds2.fubar.should == ["meh"]
49
49
  x.save
50
50
  x = FooHistory.find(@test_object.pid)
51
- x.datastreams['someData'].fubar_values.should == ["meh"]
51
+ x.datastreams['someData'].fubar.should == ["meh"]
52
52
  x.save
53
53
  end
54
54
  end