active-fedora 5.0.0.rc1 → 5.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,9 +5,6 @@ source "http://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- gem 'ruby-debug', :platform => :ruby_18
9
- # gem 'debugger', :platform => :ruby_19
10
-
11
8
  gem 'rcov', :platform => :mri_18
12
9
  gem 'simplecov', :platform => :mri_19
13
10
  gem 'simplecov-rcov', :platform => :mri_19
@@ -13,11 +13,11 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.}
14
14
 
15
15
  s.rubyforge_project = "rubyfedora"
16
- s.rubygems_version = %q{1.3.7}
16
+ s.required_ruby_version = '>= 1.9.3'
17
17
 
18
18
  s.add_dependency('rsolr')
19
- s.add_dependency('om', '~> 1.7.0.rc2')
20
- s.add_dependency('solrizer', '~>2.0.0.rc1')
19
+ s.add_dependency('om', '~> 1.8.0.rc1')
20
+ s.add_dependency('solrizer', '~>2.0.0.rc6')
21
21
  s.add_dependency("activeresource", '>= 3.0.0')
22
22
  s.add_dependency("activesupport", '>= 3.0.0')
23
23
  s.add_dependency("builder", '~> 3.0.0')
@@ -119,7 +119,8 @@ module ActiveFedora
119
119
  @target = find_target
120
120
  end
121
121
  end
122
- rescue ObjectNotFoundError
122
+ rescue ObjectNotFoundError => e
123
+ logger.error "Solr and Fedora may be out of sync:\n" + e.message
123
124
  reset
124
125
  end
125
126
  end
@@ -217,7 +217,7 @@ module ActiveFedora
217
217
  #just use index supplied instead of trying possibilities
218
218
  index = term_pointer[i-1].values.first
219
219
  solr_name_base = OM::XML::Terminology.term_hierarchical_name({bases[j]=>index},current_last)
220
- solr_name = generate_solr_symbol(solr_name_base, term.data_type)
220
+ solr_name = generate_solr_symbol(solr_name_base, term.type)
221
221
  bases.delete_at(j)
222
222
  #insert the new solr name base if found
223
223
  bases.insert(j,solr_name_base) if has_solr_name?(solr_name,solr_doc)
@@ -227,14 +227,14 @@ module ActiveFedora
227
227
  current_base = bases[j]
228
228
  bases.delete_at(j)
229
229
  solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
230
- solr_name = generate_solr_symbol(solr_name_base, term.data_type)
230
+ solr_name = generate_solr_symbol(solr_name_base, term.type)
231
231
  #check for indexes that exist until we find all nodes
232
232
  while has_solr_name?(solr_name,solr_doc) do
233
233
  #only reinsert if it exists
234
234
  bases.insert(j,solr_name_base)
235
235
  index = index + 1
236
236
  solr_name_base = OM::XML::Terminology.term_hierarchical_name({current_base=>index},current_last)
237
- solr_name = generate_solr_symbol(solr_name_base, term.data_type)
237
+ solr_name = generate_solr_symbol(solr_name_base, term.type)
238
238
  end
239
239
  end
240
240
  end
@@ -242,7 +242,7 @@ module ActiveFedora
242
242
 
243
243
  #all existing applicable solr_names have been found and we can now grab all values and build up our value array
244
244
  bases.each do |base|
245
- field_name = generate_solr_symbol(base.to_sym, term.data_type)
245
+ field_name = generate_solr_symbol(base.to_sym, term.type)
246
246
  value = (solr_doc[field_name].nil? ? solr_doc[field_name.to_s]: solr_doc[field_name])
247
247
  unless value.nil?
248
248
  value.is_a?(Array) ? values.concat(value) : values << value
@@ -251,7 +251,7 @@ module ActiveFedora
251
251
  else
252
252
  #this is not hierarchical and we can simply look for the solr name created using the terms without any indexes
253
253
  generic_field_name_base = OM::XML::Terminology.term_generic_name(*term_pointer)
254
- generic_field_name = generate_solr_symbol(generic_field_name_base, term.data_type)
254
+ generic_field_name = generate_solr_symbol(generic_field_name_base, term.type)
255
255
  value = (solr_doc[generic_field_name].nil? ? solr_doc[generic_field_name.to_s]: solr_doc[generic_field_name])
256
256
  unless value.nil?
257
257
  value.is_a?(Array) ? values.concat(value) : values << value
@@ -62,7 +62,7 @@ module ActiveFedora
62
62
  end
63
63
 
64
64
  def self.predicate_namespaces
65
- predicate_config[:predicate_namespaces] || {}
65
+ predicate_config[:predicate_namespaces] ||= {}
66
66
  end
67
67
 
68
68
  def self.predicate_mappings
@@ -37,6 +37,7 @@ module ActiveFedora
37
37
  if (xml.nil?)
38
38
  ### maybe put the template here?
39
39
  else
40
+ ensure_predicates_exist!(xml)
40
41
  RDF::RDFXML::Reader.new(xml) do |reader|
41
42
  reader.each_statement do |statement|
42
43
  literal = statement.object.kind_of?(RDF::Literal)
@@ -62,6 +63,23 @@ module ActiveFedora
62
63
  xml
63
64
  end
64
65
 
66
+ def self.ensure_predicates_exist!(xml)
67
+ statements = Nokogiri::XML(xml).xpath('//rdf:Description/*', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
68
+ predicates = statements.collect { |e| { :prefix => e.namespace.prefix, :uri => e.namespace.href, :predicate => e.name } }.uniq
69
+ predicates.each do |pred|
70
+ unless Predicates.predicate_mappings[pred[:uri]]
71
+ Predicates.predicate_mappings[pred[:uri]] = {}
72
+ if pred[:prefix] and not Predicates.predicate_namespaces.has_value?(pred[:uri])
73
+ Predicates.predicate_namespaces[pred[:prefix].to_sym] = pred[:uri]
74
+ end
75
+ end
76
+ ns = Predicates.predicate_mappings[pred[:uri]]
77
+ unless ns.invert[pred[:predicate]]
78
+ ns["#{pred[:prefix]}_#{pred[:predicate].underscore}".to_sym] = pred[:predicate]
79
+ end
80
+ end
81
+ end
82
+
65
83
  def self.short_predicate(predicate)
66
84
  # for this regex to short-circuit correctly, namespaces must be sorted into descending order by length
67
85
  if match = /^(#{Predicates.predicate_mappings.keys.sort.reverse.join('|')})(.+)$/.match(predicate.to_str)
@@ -86,6 +86,13 @@ module ActiveFedora
86
86
  result['response']['docs']
87
87
  end
88
88
 
89
+ # Get the count of records that match the query
90
+ # @param [String] query a solr query
91
+ # @returns [Integer] number of records matching
92
+ def self.count(query)
93
+ SolrService.query(query, :raw=>true, :rows=>0)['response']['numFound'].to_i
94
+ end
95
+
89
96
  def self.add(doc)
90
97
  SolrService.instance.conn.add(doc)
91
98
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "5.0.0.rc1"
2
+ VERSION = "5.0.0.rc2"
3
3
  end
@@ -141,7 +141,7 @@ xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/
141
141
  </titleInfo>
142
142
  <originInfo>
143
143
  <publisher>PUBLISHER</publisher>
144
- <dateIssued>DATE</dateIssued>
144
+ <dateIssued>FEB. 2007</dateIssued>
145
145
  </originInfo>
146
146
  <identifier type="issn">0013-8908</identifier>
147
147
  <part>
@@ -320,7 +320,54 @@ describe ActiveFedora::Base do
320
320
  end
321
321
  end
322
322
 
323
+ describe "single direction habtm" do
324
+ before :all do
325
+ class LibraryBook < ActiveFedora::Base
326
+ has_and_belongs_to_many :pages, :property=>:is_part_of
327
+ end
328
+ class Page < ActiveFedora::Base
329
+ has_many :library_books, :property=>:is_part_of
330
+ end
331
+
332
+ end
333
+ after :all do
334
+ Object.send(:remove_const, :LibraryBook)
335
+ Object.send(:remove_const, :Page)
336
+ end
337
+
338
+ describe "with a parent that has two children" do
339
+ before do
340
+ @book = LibraryBook.create
341
+ @p1 = Page.create()
342
+ @p2 = Page.create()
343
+ @book.pages = [@p1, @p2]
344
+ @book.save
345
+ end
346
+
347
+ it "should load the association stored in the parent" do
348
+ @reloaded_book = LibraryBook.find(@book.pid)
349
+ @reloaded_book.pages.should == [@p1, @p2]
350
+ end
351
+
352
+ it "should allow a parent to be deleted from the has_many association" do
353
+ @reloaded_book = LibraryBook.find(@book.pid)
354
+ @p1.library_books.delete(@reloaded_book)
355
+ @reloaded_book.save
323
356
 
357
+ @reloaded_book = LibraryBook.find(@book.pid)
358
+ @reloaded_book.pages.should == [@p2]
359
+ end
324
360
 
361
+ it "should allow a child to be deleted from the has_and_belongs_to_many association" do
362
+ pending "This isn't working and we ought to fix it"
363
+ @reloaded_book = LibraryBook.find(@book.pid)
364
+ @reloaded_book.pages.delete(@p1)
365
+ @reloaded_book.save
366
+ @p1.save
325
367
 
368
+ @reloaded_book = LibraryBook.find(@book.pid)
369
+ @reloaded_book.pages.should == [@p2]
370
+ end
371
+ end
372
+ end
326
373
  end
@@ -16,6 +16,10 @@ describe ActiveFedora::NokogiriDatastream do
16
16
 
17
17
  end
18
18
 
19
+ after(:all) do
20
+ Object.send(:remove_const, :HydrangeaArticle2)
21
+ end
22
+
19
23
  describe '.term_values' do
20
24
  before do
21
25
  @pid = "hydrangea:fixture_mods_article1"
@@ -66,4 +70,18 @@ describe ActiveFedora::NokogiriDatastream do
66
70
  @test_object.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text).should == ["Funder"]
67
71
  end
68
72
  end
73
+
74
+
75
+ describe ".to_solr" do
76
+ before do
77
+ object = HydrangeaArticle2.new
78
+ object.descMetadata.journal.issue.publication_date = Date.parse('2012-11-02')
79
+ object.save!
80
+ @test_object = HydrangeaArticle2.find(object.pid)
81
+
82
+ end
83
+ it "should solrize terms with :type=>'date' to *_dt solr terms" do
84
+ @test_object.to_solr['mods_journal_issue_publication_date_dt'].should == ['2012-11-02T00:00:00Z']
85
+ end
86
+ end
69
87
  end
@@ -38,7 +38,7 @@ module Hydra
38
38
  t.topic_tag(:proxy=>[:subject, :topic])
39
39
  # t.topic_tag(:index_as=>[:facetable],:path=>"subject", :default_content_path=>"topic")
40
40
  # This is a mods:name. The underscore is purely to avoid namespace conflicts.
41
- t.name_ {
41
+ t.name_(:index_as=>[:searchable]) {
42
42
  # this is a namepart
43
43
  t.namePart(:type=>:string, :label=>"generic name")
44
44
  # affiliations are great
@@ -58,8 +58,8 @@ module Hydra
58
58
  t.department(:proxy=>[:person,:description],:index_as=>[:facetable])
59
59
  t.organization(:ref=>:name, :attributes=>{:type=>"corporate"}, :index_as=>[:facetable])
60
60
  t.conference(:ref=>:name, :attributes=>{:type=>"conference"}, :index_as=>[:facetable])
61
- t.role {
62
- t.text(:path=>"roleTerm",:attributes=>{:type=>"text"})
61
+ t.role(:index_as=>[:searchable]) {
62
+ t.text(:path=>"roleTerm",:attributes=>{:type=>"text"}, :index_as=>[:searchable])
63
63
  t.code(:path=>"roleTerm",:attributes=>{:type=>"code"})
64
64
  }
65
65
  t.journal(:path=>'relatedItem', :attributes=>{:type=>"host"}) {
@@ -80,7 +80,7 @@ module Hydra
80
80
  }
81
81
  t.start_page(:proxy=>[:pages, :start])
82
82
  t.end_page(:proxy=>[:pages, :end])
83
- t.publication_date(:path=>"date")
83
+ t.publication_date(:path=>"date", :type=>:date, :index_as=>[:searchable])
84
84
  }
85
85
  }
86
86
  t.note
@@ -89,7 +89,7 @@ module Hydra
89
89
  }
90
90
  t.publication_url(:proxy=>[:location,:url])
91
91
  t.peer_reviewed(:proxy=>[:journal,:origin_info,:issuance], :index_as=>[:facetable])
92
- t.title(:proxy=>[:mods,:title_info, :main_title])
92
+ t.title(:proxy=>[:title_info, :main_title])
93
93
  t.journal_title(:proxy=>[:journal, :title_info, :main_title])
94
94
  end
95
95
 
@@ -273,7 +273,7 @@ describe ActiveFedora::NokogiriDatastream do
273
273
 
274
274
  it "should return correct values from solr_doc given different term pointers" do
275
275
  mock_term = mock("OM::XML::Term")
276
- mock_term.stubs(:data_type).returns(:text)
276
+ mock_term.stubs(:type).returns(:text)
277
277
  mock_terminology = mock("OM::XML::Terminology")
278
278
  mock_terminology.stubs(:retrieve_term).returns(mock_term)
279
279
  ActiveFedora::NokogiriDatastream.stubs(:terminology).returns(mock_terminology)
@@ -125,6 +125,25 @@ describe ActiveFedora::RelsExtDatastream do
125
125
  @test_obj.relationships.size.should == 5
126
126
  @test_obj.ids_for_outbound("foo").should == ["foo:bar"]
127
127
  end
128
+ it "should automatically map un-mapped predicates" do
129
+ xml = <<-EOS
130
+ <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
131
+ <rdf:Description rdf:about='info:fedora/test:sample_pid'>
132
+ <isMemberOf rdf:resource='info:fedora/demo:10' xmlns='info:fedora/fedora-system:def/relations-external#'/>
133
+ <isPartOf rdf:resource='info:fedora/demo:11' xmlns='info:fedora/fedora-system:def/relations-external#'/>
134
+ <hasPart rdf:resource='info:fedora/demo:12' xmlns='info:fedora/fedora-system:def/relations-external#'/>
135
+ <hasModel rdf:resource='info:fedora/afmodel:OtherModel' xmlns='info:fedora/fedora-system:def/model#'/>
136
+ <hasModel rdf:resource='info:fedora/afmodel:SampleModel' xmlns='info:fedora/fedora-system:def/model#'/>
137
+ <missing:hasOtherRelationship rdf:resource='info:fedora/demo:13' xmlns:missing='http://example.org/ns/missing'/>
138
+ </rdf:Description>
139
+ </rdf:RDF>
140
+ EOS
141
+ model = ActiveFedora::Base.new
142
+ new_ds = ActiveFedora::RelsExtDatastream.new(nil, nil)
143
+ new_ds.model = model
144
+ lambda { ActiveFedora::RelsExtDatastream.from_xml(xml, new_ds) }.should_not raise_exception
145
+ new_ds.to_rels_ext.should =~ /missing:hasOtherRelationship/
146
+ end
128
147
  it "should handle un-mapped literals" do
129
148
  xml = "
130
149
  <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:oai=\"http://www.openarchives.org/OAI/2.0/\">
@@ -82,6 +82,15 @@ describe ActiveFedora::SolrService do
82
82
  ActiveFedora::SolrService.query('querytext', :raw=>true).should == stub_result
83
83
  end
84
84
  end
85
+ describe ".count" do
86
+ it "should return a count of matching records" do
87
+ mock_conn = mock("Connection")
88
+ stub_result = {'response' => {'numFound'=>'7'}}
89
+ mock_conn.expects(:get).with('select', :params=>{:rows=>0, :q=>'querytext', :qt=>'standard'}).returns(stub_result)
90
+ ActiveFedora::SolrService.stubs(:instance =>stub("instance", :conn=>mock_conn))
91
+ ActiveFedora::SolrService.count('querytext').should == 7
92
+ end
93
+ end
85
94
  describe ".add" do
86
95
  it "should call solr" do
87
96
  mock_conn = mock("Connection")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc1
4
+ version: 5.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-10-25 00:00:00.000000000 Z
14
+ date: 2012-11-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rsolr
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ~>
38
38
  - !ruby/object:Gem::Version
39
- version: 1.7.0.rc2
39
+ version: 1.8.0.rc1
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,7 +44,7 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 1.7.0.rc2
47
+ version: 1.8.0.rc1
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: solrizer
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ dependencies:
52
52
  requirements:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: 2.0.0.rc1
55
+ version: 2.0.0.rc6
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ~>
62
62
  - !ruby/object:Gem::Version
63
- version: 2.0.0.rc1
63
+ version: 2.0.0.rc6
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: activeresource
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -539,10 +539,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
539
539
  requirements:
540
540
  - - ! '>='
541
541
  - !ruby/object:Gem::Version
542
- version: '0'
543
- segments:
544
- - 0
545
- hash: -1658600528590412066
542
+ version: 1.9.3
546
543
  required_rubygems_version: !ruby/object:Gem::Requirement
547
544
  none: false
548
545
  requirements: