active-fedora 1.1.13 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -13,6 +13,10 @@ tmtags
13
13
  ## VIM
14
14
  *.swp
15
15
 
16
+ ##SVN
17
+ .svn
18
+ .svn/*
19
+
16
20
  ## PROJECT::GENERAL
17
21
  coverage
18
22
  rdoc
@@ -43,9 +43,16 @@ cd /wherever/active_fedora/is
43
43
  rake spec
44
44
  </pre>
45
45
 
46
+ h2. Acknowledgements
47
+
48
+ Creator: Matt Zumwalt ("MediaShelf":http://yourmediashelf.com)
49
+
50
+ Developers:
51
+ McClain Looney & Eddie Shin ("MediaShelf":http://yourmediashelf.com), Rick Johnson (Notre Dame)
52
+
46
53
  h2. LICENSE:
47
54
 
48
- Copyright (c) 2009-2010 Matt Zumwalt
55
+ Copyright (c) 2009-2010 Matt Zumwalt & MediaShelf, LLC
49
56
 
50
57
  This program is free software: you can redistribute it and/or modify
51
58
  it under the terms of the GNU Lesser General Public License (LGPL) as
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'rake/clean'
2
- require 'lib/active_fedora'#to get VERSION
3
2
  require 'rubygems'
4
3
  load 'tasks/rspec.rake'
5
4
  $: << 'lib'
@@ -21,11 +20,13 @@ begin
21
20
  gem.add_dependency('mime-types', '>= 1.16')
22
21
  gem.add_dependency('multipart-post')
23
22
  gem.add_dependency('nokogiri')
24
- gem.add_dependency('om', '>= 0.1.9')
23
+ # gem.add_dependency('om', '>= 0.1.9')
24
+ gem.add_dependency('om', '>= 1.0')
25
+ gem.add_dependency('solrizer', '>=0.1.4')
25
26
  # gem.add_dependency('yaml')
26
27
 
27
28
  gem.add_development_dependency "rspec", ">= 1.2.9"
28
- gem.add_development_dependency "mocha", ">= 1.2.9"
29
+ gem.add_development_dependency "mocha", ">= 0.9.8"
29
30
  gem.add_development_dependency "ruby-debug"
30
31
 
31
32
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.13
1
+ 1.2.0
@@ -5,16 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active-fedora}
8
- s.version = "1.1.13"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Zumwalt", "McClain Looney"]
12
- s.date = %q{2010-07-17}
12
+ s.date = %q{2010-09-15}
13
13
  s.description = %q{ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.}
14
14
  s.email = %q{matt.zumwalt@yourmediashelf.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc",
18
17
  "README.textile"
19
18
  ]
20
19
  s.files = [
@@ -175,7 +174,6 @@ Gem::Specification.new do |s|
175
174
  "License.txt",
176
175
  "Manifest.txt",
177
176
  "PostInstall.txt",
178
- "README.rdoc",
179
177
  "README.textile",
180
178
  "Rakefile",
181
179
  "VERSION",
@@ -199,7 +197,6 @@ Gem::Specification.new do |s|
199
197
  "lib/active_fedora/relationship.rb",
200
198
  "lib/active_fedora/rels_ext_datastream.rb",
201
199
  "lib/active_fedora/semantic_node.rb",
202
- "lib/active_fedora/solr_mapper.rb",
203
200
  "lib/active_fedora/solr_service.rb",
204
201
  "lib/fedora/base.rb",
205
202
  "lib/fedora/connection.rb",
@@ -227,6 +224,7 @@ Gem::Specification.new do |s|
227
224
  "spec/fixtures/test_12.foxml.xml",
228
225
  "spec/hydrangea_fixture_mods_article1.foxml.xml",
229
226
  "spec/integration/base_file_management_spec.rb",
227
+ "spec/integration/base_find_by_fields_spec.rb",
230
228
  "spec/integration/base_loader_spec.rb",
231
229
  "spec/integration/base_spec.rb",
232
230
  "spec/integration/bug_spec.rb",
@@ -234,6 +232,7 @@ Gem::Specification.new do |s|
234
232
  "spec/integration/datastreams_crud_spec.rb",
235
233
  "spec/integration/fedora_object_spec.rb",
236
234
  "spec/integration/full_featured_model_spec.rb",
235
+ "spec/integration/metadata_datastream_helper_spec.rb",
237
236
  "spec/integration/model_spec.rb",
238
237
  "spec/integration/mods_article_integration_spec.rb",
239
238
  "spec/integration/rels_ext_datastream_spec.rb",
@@ -256,6 +255,7 @@ Gem::Specification.new do |s|
256
255
  "spec/unit/base_datastream_management_spec.rb",
257
256
  "spec/unit/base_extra_spec.rb",
258
257
  "spec/unit/base_file_management_spec.rb",
258
+ "spec/unit/base_named_datastream_spec.rb",
259
259
  "spec/unit/base_spec.rb",
260
260
  "spec/unit/connection_spec.rb",
261
261
  "spec/unit/content_model_spec.rb",
@@ -274,7 +274,6 @@ Gem::Specification.new do |s|
274
274
  "spec/unit/rf_datastream_spec.rb",
275
275
  "spec/unit/semantic_node_spec.rb",
276
276
  "spec/unit/solr_config_options_spec.rb",
277
- "spec/unit/solr_mapper_spec.rb",
278
277
  "spec/unit/solr_service_spec.rb",
279
278
  "tasks/hoe.rake",
280
279
  "tasks/rspec.rake"
@@ -287,6 +286,7 @@ Gem::Specification.new do |s|
287
286
  s.summary = %q{A convenience libary for manipulating MODS (Metadata Object Description Schema) documents.}
288
287
  s.test_files = [
289
288
  "spec/integration/base_file_management_spec.rb",
289
+ "spec/integration/base_find_by_fields_spec.rb",
290
290
  "spec/integration/base_loader_spec.rb",
291
291
  "spec/integration/base_spec.rb",
292
292
  "spec/integration/bug_spec.rb",
@@ -294,6 +294,7 @@ Gem::Specification.new do |s|
294
294
  "spec/integration/datastreams_crud_spec.rb",
295
295
  "spec/integration/fedora_object_spec.rb",
296
296
  "spec/integration/full_featured_model_spec.rb",
297
+ "spec/integration/metadata_datastream_helper_spec.rb",
297
298
  "spec/integration/model_spec.rb",
298
299
  "spec/integration/mods_article_integration_spec.rb",
299
300
  "spec/integration/rels_ext_datastream_spec.rb",
@@ -313,6 +314,7 @@ Gem::Specification.new do |s|
313
314
  "spec/unit/base_datastream_management_spec.rb",
314
315
  "spec/unit/base_extra_spec.rb",
315
316
  "spec/unit/base_file_management_spec.rb",
317
+ "spec/unit/base_named_datastream_spec.rb",
316
318
  "spec/unit/base_spec.rb",
317
319
  "spec/unit/connection_spec.rb",
318
320
  "spec/unit/content_model_spec.rb",
@@ -331,7 +333,6 @@ Gem::Specification.new do |s|
331
333
  "spec/unit/rf_datastream_spec.rb",
332
334
  "spec/unit/semantic_node_spec.rb",
333
335
  "spec/unit/solr_config_options_spec.rb",
334
- "spec/unit/solr_mapper_spec.rb",
335
336
  "spec/unit/solr_service_spec.rb"
336
337
  ]
337
338
 
@@ -345,9 +346,10 @@ Gem::Specification.new do |s|
345
346
  s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
346
347
  s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
347
348
  s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
348
- s.add_runtime_dependency(%q<om>, [">= 0.1.9"])
349
+ s.add_runtime_dependency(%q<om>, [">= 1.0"])
350
+ s.add_runtime_dependency(%q<solrizer>, [">= 0.1.4"])
349
351
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
350
- s.add_development_dependency(%q<mocha>, [">= 1.2.9"])
352
+ s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
351
353
  s.add_development_dependency(%q<ruby-debug>, [">= 0"])
352
354
  else
353
355
  s.add_dependency(%q<solr-ruby>, [">= 0.0.6"])
@@ -355,9 +357,10 @@ Gem::Specification.new do |s|
355
357
  s.add_dependency(%q<mime-types>, [">= 1.16"])
356
358
  s.add_dependency(%q<multipart-post>, [">= 0"])
357
359
  s.add_dependency(%q<nokogiri>, [">= 0"])
358
- s.add_dependency(%q<om>, [">= 0.1.9"])
360
+ s.add_dependency(%q<om>, [">= 1.0"])
361
+ s.add_dependency(%q<solrizer>, [">= 0.1.4"])
359
362
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
360
- s.add_dependency(%q<mocha>, [">= 1.2.9"])
363
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
361
364
  s.add_dependency(%q<ruby-debug>, [">= 0"])
362
365
  end
363
366
  else
@@ -366,9 +369,10 @@ Gem::Specification.new do |s|
366
369
  s.add_dependency(%q<mime-types>, [">= 1.16"])
367
370
  s.add_dependency(%q<multipart-post>, [">= 0"])
368
371
  s.add_dependency(%q<nokogiri>, [">= 0"])
369
- s.add_dependency(%q<om>, [">= 0.1.9"])
372
+ s.add_dependency(%q<om>, [">= 1.0"])
373
+ s.add_dependency(%q<solrizer>, [">= 0.1.4"])
370
374
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
371
- s.add_dependency(%q<mocha>, [">= 1.2.9"])
375
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
372
376
  s.add_dependency(%q<ruby-debug>, [">= 0"])
373
377
  end
374
378
  end
@@ -4,9 +4,9 @@ gem 'solr-ruby'
4
4
  $: << 'lib'
5
5
  require 'logger'
6
6
  require 'active_fedora/solr_service.rb'
7
- require 'active_fedora/solr_mapper.rb'
7
+ require 'solrizer/field_name_mapper'
8
8
 
9
- SOLR_DOCUMENT_ID = ActiveFedora::SolrService.mappings["id"] unless defined?(SOLR_DOCUMENT_ID)
9
+ SOLR_DOCUMENT_ID = Solrizer::FieldNameMapper.mappings["id"] unless defined?(SOLR_DOCUMENT_ID)
10
10
  ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
11
11
 
12
12
  require 'ruby-fedora'
@@ -1,6 +1,7 @@
1
1
  require 'util/class_level_inheritable_attributes'
2
2
  require 'active_fedora/model'
3
3
  require 'active_fedora/semantic_node'
4
+ require 'solrizer/field_name_mapper'
4
5
  require 'nokogiri'
5
6
 
6
7
  SOLR_DOCUMENT_ID = "id" unless defined?(SOLR_DOCUMENT_ID)
@@ -30,10 +31,13 @@ module ActiveFedora
30
31
  # This class is really a facade for a basic Fedora::FedoraObject, which is stored internally.
31
32
  class Base
32
33
  include MediaShelfClassLevelInheritableAttributes
33
- ms_inheritable_attributes :ds_specs
34
+ ms_inheritable_attributes :ds_specs, :class_named_datastreams_desc
34
35
  include Model
35
36
  include SemanticNode
36
- include SolrMapper
37
+ include Solrizer::FieldNameMapper
38
+
39
+ attr_accessor :named_datastreams_desc
40
+
37
41
 
38
42
  has_relationship "collection_members", :has_collection_member
39
43
 
@@ -98,10 +102,26 @@ module ActiveFedora
98
102
  end
99
103
 
100
104
  #Deletes a Base object, also deletes the info indexed in Solr, and
101
- #the underlying inner_object.
105
+ #the underlying inner_object. If this object is held in any relationships (ie inbound relationships
106
+ #outside of this object it will remove it from those items rels-ext as well
102
107
  def delete
108
+ inbound_relationships(:objects).each_pair do |predicate, objects|
109
+ objects.each do |obj|
110
+ if obj.respond_to?(:remove_relationship)
111
+ obj.remove_relationship(predicate,self)
112
+ obj.save
113
+ end
114
+ end
115
+ end
116
+
103
117
  Fedora::Repository.instance.delete(@inner_object)
104
- SolrService.instance.conn.delete(self.pid) if ENABLE_SOLR_UPDATES
118
+ if ENABLE_SOLR_UPDATES
119
+ ActiveFedora::SolrService.instance.conn.delete(pid)
120
+ if defined?( Solrizer::Solrizer )
121
+ solrizer = Solrizer::Solrizer.new
122
+ solrizer.solrize_delete(pid)
123
+ end
124
+ end
105
125
  end
106
126
 
107
127
 
@@ -246,7 +266,213 @@ module ActiveFedora
246
266
  def collection_members_remove()
247
267
  # will rely on SemanticNode.remove_relationship once it is implemented
248
268
  end
269
+
270
+ #
271
+ # Named Datastreams management
272
+ #
273
+ def datastream_names
274
+ named_datastreams_desc.keys
275
+ end
276
+
277
+ def add_named_file_datastream(name, file, opts={})
278
+ opts.merge!({:blob=>file,:controlGroup=>'M'})
279
+ add_named_datastream(name,opts)
280
+ end
249
281
 
282
+ # Creates a datastream with values
283
+ def add_named_datastream(name,opts={})
284
+
285
+ unless named_datastreams_desc.has_key?(name) && named_datastreams_desc[name].has_key?(:type)
286
+ raise "Failed to add datastream. Named datastream #{name} not defined for object #{pid}."
287
+ end
288
+ opts.merge!(named_datastreams_desc[name])
289
+
290
+ label = opts.has_key?(:label) ? opts[:label] : ""
291
+
292
+ #only do these steps for managed datastreams
293
+ unless (opts.has_key?(:controlGroup)&&opts[:controlGroup]!="M")
294
+ if opts.has_key?(:file)
295
+ opts.merge!({:blob => opts[:file]})
296
+ opts.delete(:file)
297
+ end
298
+
299
+ raise "You must define parameter blob for this managed datastream to load for #{pid}" unless opts.has_key?(:blob)
300
+
301
+ #if no explicit label and is a file use original file name for label
302
+ if !opts.has_key?(:label)&&opts[:blob].respond_to?(:original_filename)
303
+ label = opts[:blob].original_filename
304
+ end
305
+
306
+ if opts[:blob].respond_to?(:content_type)&&!opts[:blob].content_type.nil? && !opts.has_key?(:content_type)
307
+ opts.merge!({:content_type=>opts[:blob].content_type})
308
+ end
309
+
310
+ raise "The blob must respond to content_type or the hash must have :content_type property set" unless opts.has_key?(:content_type)
311
+
312
+ #throw error for mimeType mismatch
313
+ if named_datastreams_desc[name].has_key?(:mimeType) && !named_datastreams_desc[name][:mimeType].eql?(opts[:content_type])
314
+ raise "Content type mismatch for add datastream #{name} to #{pid}. Expected: #{named_datastreams_desc[name][:mimeType]}, Actual: #{opts[:content_type]}"
315
+ end
316
+ else
317
+ label = opts[:dsLocation] if (opts.has_key?(:dsLocation))
318
+ end
319
+
320
+ opts.merge!(:dsLabel => label)
321
+
322
+ #make sure both dsid and dsID populated if a dsid is supplied
323
+ opts.merge!(:dsid=>opts[:dsID]) if opts.has_key?(:dsID)
324
+ opts.merge!(:dsID=>opts[:dsid]) if opts.has_key?(:dsid)
325
+
326
+ ds = create_datastream(named_datastreams_desc[name][:type],opts)
327
+ #Must be of type datastream
328
+ assert_kind_of 'datastream', ds, ActiveFedora::Datastream
329
+ #make sure dsid is nil so that it uses the prefix for mapping purposes
330
+ #check dsid works for the prefix if it is set
331
+ if !ds.dsid.nil? && opts.has_key?(:prefix)
332
+ raise "dsid supplied does not conform to pattern #{opts[:prefix]}[number]" unless ds.dsid =~ /#{opts[:prefix]}[0-9]/
333
+ end
334
+
335
+ add_datastream(ds,opts)
336
+ end
337
+
338
+ ########################################################################
339
+ ### TODO: Currently requires you to update file if a managed datastream
340
+ ## but could change to allow metadata only updates as well
341
+ ########################################################################
342
+ def update_named_datastream(name, opts={})
343
+ #check that dsid provided matches existing datastream with that name
344
+ raise "You must define parameter dsid for datastream to update for #{pid}" unless opts.include?(:dsid)
345
+ raise "Datastream with name #{name} and dsid #{opts[:dsid]} does not exist for #{pid}" unless self.send("#{name}_ids").include?(opts[:dsid])
346
+ add_named_datastream(name,opts)
347
+ end
348
+
349
+ def assert_kind_of(n, o,t)
350
+ raise "Assertion failure: #{n}: #{o} is not of type #{t}" unless o.kind_of?(t)
351
+ end
352
+
353
+ def is_named_datastream?(name)
354
+ named_datastreams_desc.has_key?(name)
355
+ end
356
+
357
+ def named_datastreams
358
+ ds_values = {}
359
+ self.class.named_datastreams_desc.keys.each do |name|
360
+ ds_values.merge!({name=>self.send("#{name}")})
361
+ end
362
+ return ds_values
363
+ end
364
+
365
+ def named_datastreams_attributes
366
+ ds_values = {}
367
+ self.class.named_datastreams_desc.keys.each do |name|
368
+ ds_array = self.send("#{name}")
369
+ result_hash = {}
370
+ ds_array.each do |ds|
371
+ result_hash[ds.dsid]=ds.attributes
372
+ end
373
+ ds_values.merge!({name=>result_hash})
374
+ end
375
+ return ds_values
376
+ end
377
+
378
+ def named_datastreams_ids
379
+ dsids = {}
380
+ self.class.named_datastreams_desc.keys.each do |name|
381
+ dsid_array = self.send("#{name}_ids")
382
+ dsids[name] = dsid_array
383
+ end
384
+ return dsids
385
+ end
386
+
387
+ def datastreams_attributes
388
+ ds_values = {}
389
+ self.datastreams.each_pair do |dsid,ds|
390
+ ds_values.merge!({dsid=>ds.attributes})
391
+ end
392
+ return ds_values
393
+ end
394
+
395
+ def named_datastreams_desc
396
+ @named_datastreams_desc ||= named_datastreams_desc_from_class
397
+ end
398
+
399
+ def named_datastreams_desc_from_class
400
+ self.class.named_datastreams_desc
401
+ end
402
+
403
+ def create_datastream(type,opts={})
404
+ type.to_s.split('::').inject(Kernel) {|scope, const_name|
405
+ scope.const_get(const_name)}.new(opts)
406
+ end
407
+
408
+ def self.has_datastream(args)
409
+ unless args.has_key?(:name)
410
+ return false
411
+ end
412
+ unless args.has_key?(:prefix)
413
+ args.merge!({:prefix=>args[:name].to_s.upcase})
414
+ end
415
+ unless named_datastreams_desc.has_key?(args[:name])
416
+ named_datastreams_desc[args[:name]] = {}
417
+ end
418
+
419
+ args.merge!({:mimeType=>args[:mime_type]}) if args.has_key?(:mime_type)
420
+
421
+ unless named_datastreams_desc[args[:name]].has_key?(:type)
422
+ #default to type ActiveFedora::Datastream
423
+ args.merge!({:type => "ActiveFedora::Datastream"})
424
+ end
425
+ named_datastreams_desc[args[:name]]= args
426
+ create_named_datastream_finders(args[:name],args[:prefix])
427
+ create_named_datastream_update_methods(args[:name])
428
+ end
429
+
430
+ def self.create_named_datastream_update_methods(name)
431
+ append_file_method_name = "#{name.to_s.downcase}_file_append"
432
+ append_method_name = "#{name.to_s.downcase}_append"
433
+ #remove_method_name = "#{name.to_s.downcase}_remove"
434
+ self.send(:define_method,:"#{append_file_method_name}") do |*args|
435
+ file,opts = *args
436
+ opts ||= {}
437
+ add_named_file_datastream(name,file,opts)
438
+ end
439
+
440
+ self.send(:define_method,:"#{append_method_name}") do |*args|
441
+ opts = *args
442
+ opts ||= {}
443
+ #call add_named_datastream instead of add_file_named_datastream in case not managed datastream
444
+ add_named_datastream(name,opts)
445
+ end
446
+ end
447
+
448
+ def self.create_named_datastream_finders(name, prefix)
449
+ class_eval <<-END
450
+ def #{name}(opts={})
451
+ id_array = []
452
+ keys = datastreams.keys
453
+ id_array = keys.select {|v| v =~ /#{prefix}\d*/}
454
+ if opts[:response_format] == :id_array
455
+ return id_array
456
+ else
457
+ named_ds = []
458
+ id_array.each do |name|
459
+ if datastreams.has_key?(name)
460
+ named_ds.push(datastreams[name])
461
+ end
462
+ end
463
+ return named_ds
464
+ end
465
+ end
466
+ def #{name}_ids
467
+ #{name}(:response_format => :id_array)
468
+ end
469
+ END
470
+ end
471
+
472
+ # named datastreams desc are tracked as a hash of structure {name => args}}
473
+ def self.named_datastreams_desc
474
+ @class_named_datastreams_desc ||= {}
475
+ end
250
476
 
251
477
  #
252
478
  # Relationships Management
@@ -255,21 +481,32 @@ module ActiveFedora
255
481
  # @returns Hash of relationships, as defined by SemanticNode
256
482
  # Rely on rels_ext datastream to track relationships array
257
483
  # Overrides accessor for relationships array used by SemanticNode.
258
- def relationships
259
- return rels_ext.relationships
484
+ # If outbound_only is false, inbound relationships will be included.
485
+ def relationships(outbound_only=true)
486
+ outbound_only ? rels_ext.relationships : rels_ext.relationships.merge(:inbound=>inbound_relationships)
260
487
  end
261
488
 
262
489
  # Add a Rels-Ext relationship to the Object.
263
490
  # @param predicate
264
491
  # @param object Either a string URI or an object that responds to .pid
265
492
  def add_relationship(predicate, obj)
266
- #predicate = ActiveFedora::RelsExtDatastream.predicate_lookup(predicate)
267
493
  r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj)
268
- rels_ext.add_relationship(r)
494
+ unless relationship_exists?(r.subject, r.predicate, r.object)
495
+ rels_ext.add_relationship(r)
496
+ #need to call here to indicate update of named_relationships
497
+ @relationships_are_dirty = true
498
+ rels_ext.dirty = true
499
+ end
500
+ end
501
+
502
+ def remove_relationship(predicate, obj)
503
+ r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj)
504
+ rels_ext.remove_relationship(r)
505
+ #need to call here to indicate update of named_relationships
506
+ @relationships_are_dirty = true
269
507
  rels_ext.dirty = true
270
508
  end
271
509
 
272
-
273
510
  def inner_object # :nodoc
274
511
  @inner_object
275
512
  end
@@ -411,15 +648,60 @@ module ActiveFedora
411
648
  # solr_doc = ds.to_solr(solr_doc) if ds.class.included_modules.include?(ActiveFedora::MetadataDatastreamHelper) ||( ds.kind_of?(ActiveFedora::RelsExtDatastream) || ( ds.kind_of?(ActiveFedora::QualifiedDublinCoreDatastream) && !opts[:model_only] )
412
649
  solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ( ds.kind_of?(ActiveFedora::RelsExtDatastream) && !opts[:model_only] )
413
650
  end
651
+ begin
652
+ #logger.info("PID: '#{pid}' solr_doc put into solr: #{solr_doc.inspect}")
653
+ rescue
654
+ logger.info("Error encountered trying to output solr_doc details for pid: #{pid}")
655
+ end
414
656
  return solr_doc
415
657
  end
658
+
659
+ ###########################################################################################################
660
+ #
661
+ # This method is comparable to load_instance except it populates an object from Solr instead of Fedora.
662
+ # It is most useful for objects used in read-only displays in order to speed up loading time. If only
663
+ # a pid is passed in it will attempt to load a solr document and then populate an ActiveFedora::Base object
664
+ # based on the solr doc including any metadata datastreams and relationships.
665
+ #
666
+ # solr_doc is an optional parameter and if a value is passed it will not query solr again and just use the
667
+ # one passed to populate the object.
668
+ #
669
+ ###########################################################################################################
670
+ def self.load_instance_from_solr(pid,solr_doc=nil)
671
+ if solr_doc.nil?
672
+ result = find_by_solr(pid)
673
+ raise "Object #{pid} not found in solr" if result.nil?
674
+ solr_doc = result.hits.first
675
+ #double check pid and id in record match
676
+ raise "Object #{pid} not found in Solr" unless !result.nil? && !solr_doc.nil? && pid == solr_doc[SOLR_DOCUMENT_ID]
677
+ else
678
+ raise "Solr document record id and pid do not match" unless pid == solr_doc[SOLR_DOCUMENT_ID]
679
+ end
680
+
681
+ create_date = solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date)].nil? ? solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date).to_s] : solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date)]
682
+ modified_date = solr_doc[Solrizer::FieldNameMapper.solr_name(:system_create, :date)].nil? ? solr_doc[Solrizer::FieldNameMapper.solr_name(:system_modified, :date).to_s] : solr_doc[Solrizer::FieldNameMapper.solr_name(:system_modified, :date)]
683
+ obj = self.new({:pid=>solr_doc[SOLR_DOCUMENT_ID],:create_date=>create_date,:modified_date=>modified_date})
684
+ obj.new_object = false
685
+ #set by default to load any dependent relationship objects from solr as well
686
+ obj.load_from_solr = true
687
+ #need to call rels_ext once so it exists when iterating over datastreams
688
+ obj.rels_ext
689
+ obj.datastreams.each_value do |ds|
690
+ if ds.respond_to? (:from_solr)
691
+ ds.from_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream) || ( ds.kind_of?(ActiveFedora::RelsExtDatastream))
692
+ end
693
+ end
694
+ obj
695
+ end
416
696
 
417
697
  # Updates Solr index with self.
418
698
  def update_index
419
699
  if defined?( Solrizer::Solrizer )
700
+ #logger.info("Trying to solrize pid: #{pid}")
420
701
  solrizer = Solrizer::Solrizer.new
421
702
  solrizer.solrize( self )
422
703
  else
704
+ #logger.info("Trying to update solr for pid: #{pid}")
423
705
  SolrService.instance.conn.update(self.to_solr)
424
706
  end
425
707
  end
@@ -521,6 +803,10 @@ module ActiveFedora
521
803
  end
522
804
  end
523
805
 
806
+ def logger
807
+ @logger ||= defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT)
808
+ end
809
+
524
810
  private
525
811
  def configure_defined_datastreams
526
812
  if self.class.ds_specs
@@ -565,6 +851,5 @@ module ActiveFedora
565
851
  return result
566
852
  end
567
853
 
568
-
569
854
  end
570
855
  end