active-fedora 9.0.0.beta8 → 9.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -2
  3. data/gemfiles/{rails4.2.beta.gemfile → rails4.2.gemfile} +0 -0
  4. data/lib/active_fedora/core.rb +1 -1
  5. data/lib/active_fedora/fedora_attributes.rb +0 -1
  6. data/lib/active_fedora/indexing.rb +6 -3
  7. data/lib/active_fedora/indexing_service.rb +14 -0
  8. data/lib/active_fedora/rdf.rb +1 -1
  9. data/lib/active_fedora/rdf/datastream_indexing.rb +47 -3
  10. data/lib/active_fedora/rdf/indexing_service.rb +91 -0
  11. data/lib/active_fedora/version.rb +1 -1
  12. data/lib/generators/active_fedora/config/config_generator.rb +1 -0
  13. data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +11 -0
  14. data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +15 -0
  15. data/lib/generators/active_fedora/config/solr/templates/solr.yml +3 -6
  16. data/lib/generators/active_fedora/model/model_generator.rb +8 -6
  17. data/lib/generators/active_fedora/model/templates/datastream.rb.erb +1 -1
  18. data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +2 -2
  19. data/lib/generators/active_fedora/model/templates/model.rb.erb +35 -17
  20. data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +17 -2
  21. data/spec/integration/base_spec.rb +1 -1
  22. data/spec/integration/indexing_spec.rb +49 -0
  23. data/spec/unit/active_fedora_spec.rb +10 -9
  24. data/spec/unit/base_spec.rb +1 -32
  25. data/spec/unit/forbidden_attributes_protection_spec.rb +1 -1
  26. data/spec/unit/indexing_service_spec.rb +33 -7
  27. data/spec/unit/ntriples_datastream_spec.rb +2 -18
  28. data/spec/unit/rdf/indexing_service_spec.rb +88 -0
  29. metadata +8 -4
  30. data/lib/active_fedora/rdf/indexing.rb +0 -71
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c24dde2e32be3f35bb1d77501279572cb2695ca4
4
- data.tar.gz: 87e6796cd6ae6aac4bf464e11b2a2739f3a803fa
3
+ metadata.gz: 13402b752c7ef731670f4731f9243fa5d3b905fd
4
+ data.tar.gz: 2161503f9a2d5723f6e6756aa97a9452f23db43f
5
5
  SHA512:
6
- metadata.gz: 43b3dbe69386c97045ea8652f286c872bd3874d9c95b11b28f99203e357a7445f0287d27daefcb5c74fca1a6fab6d8f9af33389300033ff5f45218e582af8fda
7
- data.tar.gz: b6f025e13de2def11b8361663ae55510989a25e38e8fe3cf9ccc7e99ed89a87f4fef380fead464a6a13ed0ad8146a2c5b55ffab1b490aeabd223425d696371d3
6
+ metadata.gz: 84f20910ae4117da5f25c62779a7a39c795a49dee6012ec721135b338b50f414bf2733b90724cd6f64bf47202053aa7e7214e4d6bf3c04119f25f491d3e11e14
7
+ data.tar.gz: 52f71224d7d36e98844e62b3f1e66d76e59e8c2b66d80329f8376540ece57dc5495cf5b6aabdc366fa2594d0fe6efc9e48f8090efee14e8d20f5f4e4b40f7b5b
@@ -2,12 +2,16 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
- - 2.1
5
+ - 2.2
6
6
 
7
7
  gemfile:
8
8
  - gemfiles/rails4.1.gemfile
9
- - gemfiles/rails4.2.beta.gemfile
9
+ - gemfiles/rails4.2.gemfile
10
10
 
11
+ matrix:
12
+ include:
13
+ - rvm: 2.1
14
+ gemfile: gemfiles/rails4.2.gemfile
11
15
 
12
16
  notifications:
13
17
  irc: "irc.freenode.org#projecthydra"
@@ -36,7 +36,7 @@ module ActiveFedora
36
36
  def initialize(attributes_or_resource_or_url = nil, &block)
37
37
  init_internals
38
38
  attributes = initialize_resource_and_attributes(attributes_or_resource_or_url)
39
- raise IllegalOperation, "Attempting to recreate existing ldp_source" unless ldp_source.new?
39
+ raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new?
40
40
  assert_content_model
41
41
  load_attached_files
42
42
  self.attributes = attributes if attributes
@@ -3,7 +3,6 @@ module ActiveFedora
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- include RDF::Indexing
7
6
  include ActiveTriples::Properties
8
7
  include ActiveTriples::Reflection
9
8
  delegate :rdf_subject, :get_values, to: :resource
@@ -56,7 +56,7 @@ module ActiveFedora
56
56
  end
57
57
 
58
58
  def reindex_everything
59
- get_descendent_uris(ActiveFedora::Base.id_to_uri('')).each do |uri|
59
+ descendent_uris(ActiveFedora::Base.id_to_uri('')).each do |uri|
60
60
  logger.debug "Re-index everything ... #{uri}"
61
61
  ActiveFedora::Base.find(LdpResource.new(ActiveFedora.fedora.connection, uri)).update_index
62
62
  end
@@ -77,12 +77,15 @@ module ActiveFedora
77
77
  SolrInstanceLoader.new(self, id, solr_doc).object
78
78
  end
79
79
 
80
- def get_descendent_uris(uri)
80
+ def descendent_uris(uri)
81
81
  resource = Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, uri)
82
+ # GET could be slow if it's a big resource, we're using HEAD to avoid this problem,
83
+ # but this causes more requests to Fedora.
84
+ return [] unless Ldp::Response.rdf_source?(resource.head)
82
85
  immediate_descendent_uris = resource.graph.query(predicate: ::RDF::LDP.contains).map { |descendent| descendent.object.to_s }
83
86
  all_descendents_uris = [uri]
84
87
  immediate_descendent_uris.each do |descendent_uri|
85
- all_descendents_uris += get_descendent_uris(descendent_uri)
88
+ all_descendents_uris += descendent_uris(descendent_uri)
86
89
  end
87
90
  all_descendents_uris
88
91
  end
@@ -24,7 +24,13 @@ module ActiveFedora
24
24
  ProfileIndexingService
25
25
  end
26
26
 
27
+ def rdf_service
28
+ RDF::IndexingService
29
+ end
27
30
 
31
+ # Creates a solr document hash for the {#object}
32
+ # @yield [Hash] yields the solr document
33
+ # @return [Hash] the solr document
28
34
  def generate_solr_document
29
35
  solr_doc = {}
30
36
  Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable)
@@ -37,6 +43,8 @@ module ActiveFedora
37
43
  solr_doc.merge! file.to_solr(solr_doc, name: name.to_s)
38
44
  end
39
45
  solr_doc = solrize_relationships(solr_doc)
46
+ solr_doc = solrize_rdf_assertions(solr_doc)
47
+ yield(solr_doc) if block_given?
40
48
  solr_doc
41
49
  end
42
50
 
@@ -65,5 +73,11 @@ module ActiveFedora
65
73
  end
66
74
  solr_doc
67
75
  end
76
+
77
+ # Serialize the resource's RDF relationships to solr
78
+ # @param [Hash] solr_doc @deafult an empty Hash
79
+ def solrize_rdf_assertions(solr_doc = Hash.new)
80
+ solr_doc.merge rdf_service.new(object).generate_solr_document
81
+ end
68
82
  end
69
83
  end
@@ -5,7 +5,7 @@ module ActiveFedora
5
5
  autoload :Fcrepo
6
6
  autoload :Fcrepo4
7
7
  autoload :Ldp
8
- autoload :Indexing
8
+ autoload :IndexingService
9
9
  autoload :Identifiable
10
10
  autoload :Persistence
11
11
  autoload :RelsExt
@@ -1,11 +1,55 @@
1
1
  module ActiveFedora::RDF
2
2
  module DatastreamIndexing
3
3
  extend ActiveSupport::Concern
4
- include Indexing
5
4
 
6
- def apply_prefix(name, file_path)
7
- prefix(file_path) + name.to_s
5
+ def to_solr(solr_doc={}, opts={}) # :nodoc:
6
+ super.tap do |solr_doc|
7
+ solrize_rdf_assertions(opts[:name], solr_doc)
8
+ end
8
9
  end
10
+
11
+ # Gives the primary solr name for a column. If there is more than one indexer on the field definition, it gives the first
12
+ def primary_solr_name(field, file_path)
13
+ config = self.class.config_for_term_or_uri(field)
14
+ return nil unless config # punt on index names for deep nodes!
15
+ if behaviors = config.behaviors
16
+ behaviors.each do |behavior|
17
+ result = ActiveFedora::SolrQueryBuilder.solr_name(apply_prefix(field, file_path), behavior, type: config.type)
18
+ return result if Solrizer::DefaultDescriptors.send(behavior).evaluate_suffix(:text).stored?
19
+ end
20
+ raise RuntimeError "no stored fields were found"
21
+ end
22
+ end
23
+
24
+
25
+ module ClassMethods
26
+ def indexer
27
+ ActiveFedora::RDF::IndexingService
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ def indexing_service
34
+ @indexing_service ||= self.class.indexer.new(self)
35
+ end
36
+
37
+ # Serialize the datastream's RDF relationships to solr
38
+ # @param [String] file_path used to prefix the keys in the solr document
39
+ # @param [Hash] solr_doc @default an empty Hash
40
+ def solrize_rdf_assertions(file_path, solr_doc = {})
41
+ solr_doc.merge! indexing_service.generate_solr_document(prefix_method(file_path))
42
+ end
43
+
44
+ # Returns a function that takes field name and returns a solr document key
45
+ def prefix_method(file_path)
46
+ lambda { |field_name| apply_prefix(field_name, file_path) }
47
+ end
48
+
49
+ def apply_prefix(name, file_path)
50
+ prefix(file_path) + name.to_s
51
+ end
52
+
9
53
  end
10
54
  end
11
55
 
@@ -0,0 +1,91 @@
1
+ module ActiveFedora::RDF
2
+ class IndexingService
3
+ include Solrizer::Common
4
+ attr_reader :object
5
+
6
+ # @param obj [#resource, #rdf_subject] the object to build an solr document for. Its class must respond to 'properties'
7
+ # @param prefix_method [Lambda] This method gets the original name of the field and the options passed in. It should return the name of the field in the solr document
8
+ def initialize(obj)
9
+ @object = obj
10
+ end
11
+
12
+ # Creates a solr document hash for the rdf assertions of the {#object}
13
+ # @yield [Hash] yields the solr document
14
+ # @return [Hash] the solr document
15
+ def generate_solr_document(prefix_method = nil)
16
+ solr_doc = add_assertions(prefix_method)
17
+ yield(solr_doc) if block_given?
18
+ solr_doc
19
+ end
20
+
21
+ protected
22
+
23
+ def add_assertions(prefix_method, solr_doc = {})
24
+ fields.each do |field_key, field_info|
25
+ values = resource.get_values(field_key)
26
+ solr_field_key = solr_document_field_name(field_key, prefix_method)
27
+ Array(values).each do |val|
28
+ append_to_solr_doc(solr_doc, solr_field_key, field_info, val)
29
+ end
30
+ end
31
+ solr_doc
32
+ end
33
+
34
+ # Override this in order to allow one field to be expanded into more than one:
35
+ # example:
36
+ # def append_to_solr_doc(solr_doc, field_key, field_info, val)
37
+ # Solrizer.set_field(solr_doc, 'lcsh_subject_uri', val.to_uri, :symbol)
38
+ # Solrizer.set_field(solr_doc, 'lcsh_subject_label', val.to_label, :searchable)
39
+ # end
40
+ def append_to_solr_doc(solr_doc, solr_field_key, field_info, val)
41
+ self.class.create_and_insert_terms(solr_field_key,
42
+ solr_document_field_value(val),
43
+ field_info[:behaviors], solr_doc)
44
+ end
45
+
46
+ def solr_document_field_name(field_key, prefix_method)
47
+ if prefix_method
48
+ prefix_method.call(field_key)
49
+ else
50
+ field_key.to_s
51
+ end
52
+ end
53
+
54
+ def solr_document_field_value(val)
55
+ case val
56
+ when ::RDF::URI
57
+ val.to_s
58
+ when ActiveTriples::Resource
59
+ val.solrize
60
+ else
61
+ val
62
+ end
63
+ end
64
+
65
+ def resource
66
+ object.resource
67
+ end
68
+
69
+ def properties
70
+ object.class.properties
71
+ end
72
+
73
+ # returns a Hash, e.g.: {field => { values: [], type: :something, behaviors: [] }, ...}
74
+ def fields
75
+ field_map = {}.with_indifferent_access
76
+
77
+ properties.each do |name, config|
78
+ type = config[:type]
79
+ behaviors = config[:behaviors]
80
+ next unless type and behaviors
81
+ next if config[:class_name] && config[:class_name] < ActiveFedora::Base
82
+ resource.query(subject: object.rdf_subject, predicate: config[:predicate]).each_statement do |statement|
83
+ field_map[name] ||= { values: [], type: type, behaviors: behaviors}
84
+ field_map[name][:values] << statement.object.to_s
85
+ end
86
+ end
87
+ field_map
88
+ end
89
+
90
+ end
91
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.0.0.beta8"
2
+ VERSION = "9.0.0.rc1"
3
3
  end
@@ -3,6 +3,7 @@ require 'rails/generators'
3
3
  module ActiveFedora
4
4
  class ConfigGenerator < Rails::Generators::Base
5
5
  def generate_configs
6
+ generate('active_fedora:config:fedora')
6
7
  generate('active_fedora:config:solr')
7
8
  end
8
9
  end
@@ -0,0 +1,11 @@
1
+ require 'rails/generators'
2
+
3
+ module ActiveFedora
4
+ class Config::FedoraGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def generate
8
+ copy_file('fedora.yml', 'config/fedora.yml')
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ development:
2
+ user: fedoraAdmin
3
+ password: fedoraAdmin
4
+ url: http://127.0.0.1:8983/fedora/rest
5
+ base_path: /dev
6
+ test:
7
+ user: fedoraAdmin
8
+ password: fedoraAdmin
9
+ url: http://localhost:8983/fedora/rest
10
+ base_path: /test
11
+ production:
12
+ user: fedoraAdmin
13
+ password: fedoraAdmin
14
+ url: http://127.0.0.1:8983/fedora/rest
15
+ base_path: /prod
@@ -1,10 +1,7 @@
1
- # This is a sample config file that does not have multiple solr instances. You will also need to be sure to
2
- # edit the fedora.yml file to match the solr URL for active-fedora.
1
+ # This is a sample config file that points to a solr server for each environment
3
2
  development:
4
3
  url: http://localhost:8983/solr/development
5
- test: &TEST
4
+ test:
6
5
  url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8983}/solr/test" %>
7
- cucumber:
8
- <<: *TEST
9
6
  production:
10
- url: http://your.production.server:8080/bl_solr/core0
7
+ url: http://your.production.server:8080/bl_solr/core0
@@ -5,16 +5,18 @@ module ActiveFedora
5
5
  source_root ::File.expand_path('../templates', __FILE__)
6
6
  check_class_collision
7
7
 
8
- class_option :directory, :type => :string, :default => 'models', :desc => "Which directory to generate? (i.e. app/DIRECTORY)"
9
- class_option :datastream_directory, :type => :string, :default => 'models/datastreams', :desc => "Which datastream directory to generate? (i.e. models/datastreams)"
10
- class_option :has_file_datastream, :type => :string, :default => nil, :desc => "Name a file datastream to create"
11
- class_option :descMetadata, :type => :string, :default => nil, :desc => "Add a descMetadata metadata datastream"
8
+ class_option :directory, type: :string, default: 'models', desc: "Which directory to generate? (i.e. app/DIRECTORY)"
9
+ class_option :datastream_directory, type: :string, default: 'models/datastreams', desc: "Which datastream directory to generate? (i.e. models/datastreams)"
10
+ class_option :contains, type: :string, default: nil, desc: "Name a file to attach"
11
+ class_option :datastream, type: :string, default: nil, desc: "Name a metadata datastream to create"
12
12
 
13
13
  def install
14
14
  template('model.rb.erb', ::File.join('app', directory, "#{file_name}.rb"))
15
- template('datastream.rb.erb', ::File.join('app', datastream_directory, "#{file_name}_metadata.rb"))
16
15
  template('model_spec.rb.erb', ::File.join('spec', directory, "#{file_name}_spec.rb"))
17
- template('datastream_spec.rb.erb', ::File.join('spec', datastream_directory, "#{file_name}_metadata_spec.rb"))
16
+ if options[:datastream]
17
+ template('datastream.rb.erb', ::File.join('app', datastream_directory, "#{file_name}_metadata.rb"))
18
+ template('datastream_spec.rb.erb', ::File.join('spec', datastream_directory, "#{file_name}_metadata_spec.rb"))
19
+ end
18
20
  end
19
21
 
20
22
  protected
@@ -1,5 +1,5 @@
1
1
  # Generated via
2
- # `rails generate active_fedora::model <%= class_name %>`
2
+ # `rails generate active_fedora:model <%= class_name %>`
3
3
  class <%= class_name %>Metadata < ActiveFedora::OmDatastream
4
4
 
5
5
  # Define a terminology for parsing this XML document
@@ -1,6 +1,6 @@
1
1
  # Generated via
2
- # `rails generate active_fedora::model <%= class_name %>`
3
- require 'spec_helper'
2
+ # `rails generate active_fedora:model <%= class_name %>`
3
+ require 'rails_helper'
4
4
 
5
5
  describe <%= class_name %>Metadata do
6
6
  it 'should have a title' do
@@ -1,28 +1,46 @@
1
1
  # Generated via
2
- # `rails generate active_fedora::model <%= class_name %>`
2
+ # `rails generate active_fedora:model <%= class_name %>`
3
3
  class <%= class_name %> < ActiveFedora::Base
4
- <% if options['descMetadata'] %>
5
- has_metadata "descMetadata", type: <%= options['descMetadata'] %>
4
+ <% if options['datastream'] %>
5
+ contains :descMetadata, class_name: "<%= options['datastream'] %>"
6
6
  <% else %>
7
- # Creating a #descMetadata method that returns the datastream.
7
+ # Define some properties to store:
8
8
  #
9
- has_metadata "descMetadata", type: <%= class_name %>Metadata
9
+ property :title, predicate: ::RDF::DC.title do |index|
10
+ index.as :stored_searchable, :facetable
11
+ end
12
+ property :creator, predicate: ::RDF::DC.creator do |index|
13
+ index.as :stored_searchable, :facetable
14
+ end
15
+ property :contributor, predicate: ::RDF::DC.contributor do |index|
16
+ index.as :stored_searchable, :facetable
17
+ end
18
+ property :description, predicate: ::RDF::DC.description do |index|
19
+ index.as :stored_searchable
20
+ end
10
21
  <%- end -%>
11
- <% if options['has_file_datastream'] %>
12
- has_file_datastream "<%= options['has_file_datastream'] %>"
22
+ <% if options['contains'] %>
23
+ contains :<%= options['contains'] %>"
13
24
  <% else %>
14
- # Uncomment the following lines to add an #attachment method that is a
15
- # file_datastream:
25
+ # Uncomment the following lines to add an #attachment method that is a file
16
26
  #
17
- # has_file_datastream "attachment"
27
+ # contains "attachment"
18
28
  <% end %>
19
- # "If you need to add additional attributes to the SOLR document, define the
20
- # #to_solr method and make sure to use super"
21
29
  #
22
- # def to_solr(solr_document={}, options={})
23
- # super(solr_document, options)
24
- # solr_document["my_attribute_s"] = my_attribute
25
- # return solr_document
30
+ # If you need to add additional attributes to the SOLR document, extend the default indexer:
31
+ #
32
+ # def indexer
33
+ # MyApp::IndexingService
34
+ # end
35
+ #
36
+ # This can go into app/services/my_app/indexing_service.rb
37
+ # module MyApp
38
+ # class IndexingService < ActiveFedora::IndexingService
39
+ # def generate_solr_document
40
+ # super.tap do |solr_doc|
41
+ # solr_doc["my_attribute_s"] = object.my_attribute
42
+ # end
43
+ # end
44
+ # end
26
45
  # end
27
-
28
46
  end
@@ -1,6 +1,6 @@
1
1
  # Generated via
2
- # `rails generate active_fedora::model <%= class_name %>`
3
- require 'spec_helper'
2
+ # `rails generate active_fedora:model <%= class_name %>`
3
+ require 'rails_helper'
4
4
  require 'active_fedora/test_support'
5
5
 
6
6
  describe <%= class_name %> do
@@ -16,8 +16,23 @@ describe <%= class_name %> do
16
16
  end
17
17
  end
18
18
 
19
+ <% if options['datastream'] %>
19
20
  it 'should have a descMetadata datastream' do
20
21
  expect(subject.descMetadata).to be_kind_of <%= options['descMetadata'] ? options['descMetadata'] : "#{class_name}Metadata" %>
21
22
  end
23
+ <% else %>
24
+ it 'should have a title' do
25
+ subject.title = ['War and Peace']
26
+ expect(subject.title).to eq ['War and Peace']
27
+ end
28
+
29
+ describe "#to_solr" do
30
+ subject { <%= class_name %>.new(title: ['War and Peace']).to_solr }
31
+
32
+ it 'should have a title' do
33
+ expect(subject['title_tesim']).to eq ['War and Peace']
34
+ end
35
+ end
36
+ <% end %>
22
37
 
23
38
  end
@@ -46,7 +46,7 @@ describe "A base object with metadata" do
46
46
  end
47
47
  describe "when trying to create it again" do
48
48
  it "should raise an error" do
49
- expect { MockAFBaseRelationship.create(id: @release.id) }.to raise_error(ActiveFedora::IllegalOperation)
49
+ expect { MockAFBaseRelationship.create(id: @release.id) }.to raise_error(ActiveFedora::IllegalOperation, "Attempting to recreate existing ldp_source: `#{@release.uri}'")
50
50
  @release.reload
51
51
  expect(@release.foo.person).to include('test foo content')
52
52
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ @@last_id = 0
3
+
4
+ describe ActiveFedora::Base do
5
+ describe "descendent_uris" do
6
+
7
+ before :each do
8
+ ids.each do |id|
9
+ ActiveFedora::Base.create id: id
10
+ end
11
+ end
12
+
13
+ def root_uri(ids=[])
14
+ ActiveFedora::Base.id_to_uri(ids.first)
15
+ end
16
+
17
+ context 'when there there are no descendents' do
18
+
19
+ let(:ids) { ['foo'] }
20
+
21
+ it 'returns an array containing only the URI passed to it' do
22
+ expect(ActiveFedora::Base.descendent_uris(root_uri(ids))).to eq ids.map {|id| ActiveFedora::Base.id_to_uri(id) }
23
+ end
24
+ end
25
+
26
+ context 'when there are > 1 descendents' do
27
+
28
+ let(:ids) { ['foo', 'foo/bar', 'foo/bar/chu'] }
29
+
30
+ it 'returns an array containing the URI passed to it, as well as all descendent URIs' do
31
+ expect(ActiveFedora::Base.descendent_uris(root_uri(ids))).to eq ids.map {|id| ActiveFedora::Base.id_to_uri(id) }
32
+ end
33
+ end
34
+
35
+ context 'when some of the decendants are not RDFSources' do
36
+ let(:ids) { ['foo', 'foo/bar'] }
37
+ let(:datastream) { ActiveFedora::Datastream.new(ActiveFedora::Base.id_to_uri('foo/bar/bax')) }
38
+
39
+ before do
40
+ datastream.content = "Hello!!!"
41
+ datastream.save
42
+ end
43
+
44
+ it "should not put the datastream in the decendants list" do
45
+ expect(ActiveFedora::Base.descendent_uris(root_uri(ids))).not_to include datastream.uri
46
+ end
47
+ end
48
+ end
49
+ end
@@ -4,10 +4,11 @@ require 'config_helper'
4
4
  # For testing Module-level methods like ActiveFedora.init
5
5
 
6
6
  describe ActiveFedora do
7
-
8
- before(:each) do
7
+
8
+ before do
9
9
  restore_spec_configuration
10
10
  end
11
+
11
12
  after :all do
12
13
  unstub_rails
13
14
  # Restore to default fedora configs
@@ -51,10 +52,10 @@ describe ActiveFedora do
51
52
  end
52
53
  end
53
54
  end
54
-
55
+
55
56
  describe ".init" do
56
-
57
- after(:each) do
57
+
58
+ after do
58
59
  # Restore to default fedora configs
59
60
  ActiveFedora.init(:environment => "test", :fedora_config_path => File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml"))
60
61
  end
@@ -94,7 +95,7 @@ describe ActiveFedora do
94
95
  describe "with no explicit config path" do
95
96
  it "should look for the file in the path defined at Rails.root" do
96
97
  allow(ActiveFedora::SolrService).to receive(:load_mappings) #necessary or else it will load the solrizer config and it breaks other tests in the suite.
97
-
98
+
98
99
  stub_rails(:root=>File.join(File.dirname(__FILE__),"../fixtures/rails_root"))
99
100
  ActiveFedora.init()
100
101
  expect(ActiveFedora.config.credentials[:url]).to eq "http://testhost.com:8983/fedora"
@@ -103,7 +104,7 @@ describe ActiveFedora do
103
104
  end
104
105
  end
105
106
  end
106
-
107
+
107
108
  describe "#class_from_string" do
108
109
  before do
109
110
  module ParentClass
@@ -115,8 +116,8 @@ describe ActiveFedora do
115
116
  end
116
117
  it "should return class constants based on strings" do
117
118
  expect(ActiveFedora.class_from_string("Om")).to eq Om
118
- expect(ActiveFedora.class_from_string("ActiveFedora::RDF::Indexing")).to eq ActiveFedora::RDF::Indexing
119
- expect(ActiveFedora.class_from_string("Indexing", ActiveFedora::RDF)).to eq ActiveFedora::RDF::Indexing
119
+ expect(ActiveFedora.class_from_string("ActiveFedora::RDF::IndexingService")).to eq ActiveFedora::RDF::IndexingService
120
+ expect(ActiveFedora.class_from_string("IndexingService", ActiveFedora::RDF)).to eq ActiveFedora::RDF::IndexingService
120
121
  end
121
122
 
122
123
  it "should find sibling classes" do
@@ -12,7 +12,7 @@ describe ActiveFedora::Base do
12
12
 
13
13
  describe "reindex_everything" do
14
14
  it "should call update_index on every object represented in the sitemap" do
15
- allow(ActiveFedora::Base).to receive(:get_descendent_uris) { ['http://localhost/test/XXX', 'http://localhost/test/YYY', 'http://localhost/test/ZZZ'] }
15
+ allow(ActiveFedora::Base).to receive(:descendent_uris) { ['http://localhost/test/XXX', 'http://localhost/test/YYY', 'http://localhost/test/ZZZ'] }
16
16
  mock_update = double(:mock_obj)
17
17
  expect(mock_update).to receive(:update_index).exactly(3).times
18
18
  expect(ActiveFedora::Base).to receive(:find).with(instance_of ActiveFedora::LdpResource ).and_return(mock_update).exactly(3).times
@@ -20,37 +20,6 @@ describe ActiveFedora::Base do
20
20
  end
21
21
  end
22
22
 
23
- describe "get_descendent_uris" do
24
-
25
- before :each do
26
- ids.each do |id|
27
- ActiveFedora::Base.create id: id
28
- end
29
- end
30
-
31
- def root_uri(ids=[])
32
- ActiveFedora::Base.id_to_uri(ids.first)
33
- end
34
-
35
- context 'when there there are no descendents' do
36
-
37
- let(:ids) { ['foo'] }
38
-
39
- it 'returns an array containing only the URI passed to it' do
40
- expect(ActiveFedora::Base.get_descendent_uris(root_uri(ids))).to eq ids.map {|id| ActiveFedora::Base.id_to_uri(id) }
41
- end
42
- end
43
-
44
- context 'when there are > 1 descendents' do
45
-
46
- let(:ids) { ['foo', 'foo/bar', 'foo/bar/chu'] }
47
-
48
- it 'returns an array containing the URI passed to it, as well as all descendent URIs' do
49
- expect(ActiveFedora::Base.get_descendent_uris(root_uri(ids))).to eq ids.map {|id| ActiveFedora::Base.id_to_uri(id) }
50
- end
51
- end
52
- end
53
-
54
23
  describe "With a test class" do
55
24
  before :each do
56
25
  class FooHistory < ActiveFedora::Base
@@ -44,7 +44,7 @@ describe "Mass assignment protection" do
44
44
 
45
45
  context "permitted attributes" do
46
46
  let(:params) { ProtectedParams.new(first_name: 'Guille', gender: 'm').permit! }
47
- it "cannot be used for mass assignment" do
47
+ it "can be used for mass assignment" do
48
48
  expect { Person.new(params) }.not_to raise_error
49
49
  end
50
50
  end
@@ -4,20 +4,46 @@ describe ActiveFedora::IndexingService do
4
4
  let(:indexer) { described_class.new(object) }
5
5
  let(:object) { ActiveFedora::Base.new }
6
6
 
7
- subject { indexer.send(:solrize_relationships) }
8
-
9
7
  describe "#solrize_relationships" do
10
- let(:person_reflection) { double('person', foreign_key: 'person_id', kind_of?: true, solr_key: 'http://fedora.info/definitions/v4/rels-ext#isMemberOf_ssim') }
11
- let(:location_reflection) { double('location', foreign_key: 'location_id', kind_of?: true, solr_key: 'http://fedora.info/definitions/v4/rels-ext#isPartOf_ssim') }
8
+ subject { indexer.send(:solrize_relationships) }
9
+ let(:person_reflection) { double('person', foreign_key: 'person_id', kind_of?: true, solr_key: member_of) }
10
+ let(:location_reflection) { double('location', foreign_key: 'location_id', kind_of?: true, solr_key: part_of) }
12
11
  let(:reflections) { { 'person' => person_reflection, 'location' => location_reflection } }
13
12
 
14
- it "should serialize the relationships into a Hash" do
13
+ let(:member_of) { ActiveFedora::SolrQueryBuilder.solr_name("http://fedora.info/definitions/v4/rels-ext#isMemberOf", :symbol) }
14
+ let(:part_of) { ActiveFedora::SolrQueryBuilder.solr_name("http://fedora.info/definitions/v4/rels-ext#isPartOf", :symbol) }
15
+
16
+ before do
15
17
  expect(object).to receive(:[]).with('person_id').and_return('info:fedora/demo:10')
16
18
  expect(object).to receive(:[]).with('location_id').and_return('info:fedora/demo:11')
17
19
  expect(object.class).to receive(:reflections).and_return(reflections)
18
- expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("http://fedora.info/definitions/v4/rels-ext#isMemberOf", :symbol)]).to eq "info:fedora/demo:10"
19
- expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("http://fedora.info/definitions/v4/rels-ext#isPartOf", :symbol)]).to eq "info:fedora/demo:11"
20
+ end
21
+
22
+ it "should serialize the relationships into a Hash" do
23
+ expect(subject[member_of]).to eq "info:fedora/demo:10"
24
+ expect(subject[part_of]).to eq "info:fedora/demo:11"
20
25
  end
21
26
  end
22
27
 
28
+ describe "#generate_solr_document" do
29
+ context "when no block is passed" do
30
+ subject { indexer.generate_solr_document }
31
+ it "should produce a document" do
32
+ expect(subject['has_model_ssim']).to eq ['ActiveFedora::Base']
33
+ end
34
+ end
35
+
36
+ context "when a block is passed" do
37
+ subject do
38
+ indexer.generate_solr_document do |solr_doc|
39
+ solr_doc['noid'] = '12345'
40
+ end
41
+ end
42
+
43
+ it "should produce and yield the document" do
44
+ expect(subject['has_model_ssim']).to eq ['ActiveFedora::Base']
45
+ expect(subject['noid']).to eq '12345'
46
+ end
47
+ end
48
+ end
23
49
  end
@@ -75,8 +75,8 @@ describe ActiveFedora::NtriplesRDFDatastream do
75
75
  @two = ActiveFedora::RDFDatastream.new
76
76
  end
77
77
  it "should generate predictable prexies" do
78
- expect(@one.apply_prefix("baz", 'myFoobar')).to eq 'my_foobar__baz'
79
- expect(@two.apply_prefix("baz", 'myQuix')).to eq 'my_quix__baz'
78
+ expect(@one.send(:apply_prefix, "baz", 'myFoobar')).to eq 'my_foobar__baz'
79
+ expect(@two.send(:apply_prefix, "baz", 'myQuix')).to eq 'my_quix__baz'
80
80
  end
81
81
  end
82
82
 
@@ -199,22 +199,6 @@ describe ActiveFedora::NtriplesRDFDatastream do
199
199
  Object.send(:remove_const, :Foo)
200
200
  end
201
201
 
202
-
203
- describe ".fields()" do
204
- it "should return the right fields" do
205
- expect(@obj.send(:fields).keys).to eq ["created", "title", "publisher", "based_near", "related_url"]
206
- end
207
- it "should return the right values" do
208
- fields = @obj.send(:fields)
209
- expect(fields[:related_url][:values]).to eq ["http://example.org/blogtastic/"]
210
- expect(fields[:based_near][:values]).to eq ["Tacoma, WA", "Renton, WA"]
211
- end
212
- it "should return the right type information" do
213
- fields = @obj.send(:fields)
214
- expect(fields[:created][:type]).to eq :date
215
- end
216
- end
217
-
218
202
  describe ".to_solr()" do
219
203
  subject { @obj.to_solr({}, name: 'solrRdf') }
220
204
  it "should return the right fields" do
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::RDF::IndexingService do
4
+ before do
5
+ class MyDatastream < ActiveFedora::NtriplesRDFDatastream
6
+ property :created, predicate: ::RDF::DC.created do |index|
7
+ index.as :sortable, :displayable
8
+ index.type :date
9
+ end
10
+ property :title, predicate: ::RDF::DC.title do |index|
11
+ index.as :stored_searchable, :sortable
12
+ index.type :text
13
+ end
14
+ property :publisher, predicate: ::RDF::DC.publisher do |index|
15
+ index.as :facetable, :sortable, :stored_searchable
16
+ end
17
+ property :based_near, predicate: ::RDF::FOAF.based_near do |index|
18
+ index.as :facetable, :stored_searchable
19
+ index.type :text
20
+ end
21
+ property :related_url, predicate: ::RDF::RDFS.seeAlso do |index|
22
+ index.as :stored_searchable
23
+ end
24
+ property :rights, predicate: ::RDF::DC.rights
25
+ end
26
+ end
27
+
28
+ after do
29
+ Object.send(:remove_const, :MyDatastream)
30
+ end
31
+
32
+ let(:f2) do
33
+ MyDatastream.new.tap do |obj|
34
+ obj.created = Date.parse("2012-03-04")
35
+ obj.title = "Of Mice and Men, The Sequel"
36
+ obj.publisher = "Bob's Blogtastic Publishing"
37
+ obj.based_near = ["Tacoma, WA", "Renton, WA"]
38
+ obj.related_url = "http://example.org/blogtastic/"
39
+ obj.rights = "Totally open, y'all"
40
+ end
41
+ end
42
+
43
+ let(:indexer) { described_class.new(f2) }
44
+
45
+ describe "#generate_solr_document" do
46
+ subject { indexer.generate_solr_document(lambda { |key| "solr_rdf__#{key}" }) }
47
+ it "should return the right fields" do
48
+ expect(subject.keys).to include(ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__related_url", type: :string),
49
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__publisher", type: :string),
50
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__publisher", :sortable),
51
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__publisher", :facetable),
52
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__created", :sortable, type: :date),
53
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__created", :displayable),
54
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__title", type: :string),
55
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__title", :sortable),
56
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__based_near", type: :string),
57
+ ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__based_near", :facetable))
58
+
59
+ end
60
+
61
+ it "should return the right values" do
62
+ expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__related_url", type: :string)]).to eq ["http://example.org/blogtastic/"]
63
+ expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__based_near", type: :string)]).to eq ["Tacoma, WA","Renton, WA"]
64
+ expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__based_near", :facetable)]).to eq ["Tacoma, WA","Renton, WA"]
65
+ expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__publisher", type: :string)]).to eq ["Bob's Blogtastic Publishing"]
66
+ expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__publisher", :sortable)]).to eq "Bob's Blogtastic Publishing"
67
+ expect(subject[ActiveFedora::SolrQueryBuilder.solr_name("solr_rdf__publisher", :facetable)]).to eq ["Bob's Blogtastic Publishing"]
68
+ end
69
+ end
70
+
71
+ describe "#fields" do
72
+ let(:fields) { indexer.send(:fields) }
73
+
74
+ it "should return the right fields" do
75
+ expect(fields.keys).to eq ["created", "title", "publisher", "based_near", "related_url"]
76
+ end
77
+
78
+ it "should return the right values" do
79
+ expect(fields[:related_url][:values]).to eq ["http://example.org/blogtastic/"]
80
+ expect(fields[:based_near][:values]).to eq ["Tacoma, WA", "Renton, WA"]
81
+ end
82
+
83
+ it "should return the right type information" do
84
+ expect(fields[:created][:type]).to eq :date
85
+ end
86
+ end
87
+
88
+ end
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: 9.0.0.beta8
4
+ version: 9.0.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-12-19 00:00:00.000000000 Z
13
+ date: 2015-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -281,7 +281,7 @@ files:
281
281
  - config/solr_mappings_af_0.1.yml
282
282
  - config/solr_mappings_bl_2.4.yml
283
283
  - gemfiles/rails4.1.gemfile
284
- - gemfiles/rails4.2.beta.gemfile
284
+ - gemfiles/rails4.2.gemfile
285
285
  - lib/active-fedora.rb
286
286
  - lib/active_fedora.rb
287
287
  - lib/active_fedora/association_relation.rb
@@ -357,7 +357,7 @@ files:
357
357
  - lib/active_fedora/rdf/datastream_indexing.rb
358
358
  - lib/active_fedora/rdf/fcrepo.rb
359
359
  - lib/active_fedora/rdf/fcrepo4.rb
360
- - lib/active_fedora/rdf/indexing.rb
360
+ - lib/active_fedora/rdf/indexing_service.rb
361
361
  - lib/active_fedora/rdf/ldp.rb
362
362
  - lib/active_fedora/rdf/ntriples_rdf_datastream.rb
363
363
  - lib/active_fedora/rdf/persistence.rb
@@ -395,6 +395,8 @@ files:
395
395
  - lib/active_fedora/with_metadata/metadata_node.rb
396
396
  - lib/generators/active_fedora/config/USAGE
397
397
  - lib/generators/active_fedora/config/config_generator.rb
398
+ - lib/generators/active_fedora/config/fedora/fedora_generator.rb
399
+ - lib/generators/active_fedora/config/fedora/templates/fedora.yml
398
400
  - lib/generators/active_fedora/config/solr/solr_generator.rb
399
401
  - lib/generators/active_fedora/config/solr/templates/jetty.yml
400
402
  - lib/generators/active_fedora/config/solr/templates/solr.yml
@@ -445,6 +447,7 @@ files:
445
447
  - spec/integration/full_featured_model_spec.rb
446
448
  - spec/integration/has_and_belongs_to_many_associations_spec.rb
447
449
  - spec/integration/has_many_associations_spec.rb
450
+ - spec/integration/indexing_spec.rb
448
451
  - spec/integration/json_serialization_spec.rb
449
452
  - spec/integration/model_spec.rb
450
453
  - spec/integration/nested_attribute_spec.rb
@@ -514,6 +517,7 @@ files:
514
517
  - spec/unit/qualified_dublin_core_datastream_spec.rb
515
518
  - spec/unit/query_result_builder_spec.rb
516
519
  - spec/unit/query_spec.rb
520
+ - spec/unit/rdf/indexing_service_spec.rb
517
521
  - spec/unit/rdf_datastream_spec.rb
518
522
  - spec/unit/rdf_resource_datastream_spec.rb
519
523
  - spec/unit/rdf_vocab_spec.rb
@@ -1,71 +0,0 @@
1
- module ActiveFedora
2
- module RDF
3
- module Indexing
4
- extend ActiveSupport::Concern
5
- included do
6
- include Solrizer::Common
7
- end
8
-
9
- def apply_prefix(name, file_path)
10
- name.to_s
11
- end
12
-
13
- def to_solr(solr_doc={}, opts={}) # :nodoc:
14
- super.tap do |solr_doc|
15
- fields.each do |field_key, field_info|
16
- values = resource.get_values(field_key)
17
- Array(values).each do |val|
18
- val = case val
19
- when ::RDF::URI, ActiveTriples::Term
20
- val.to_s
21
- when ActiveTriples::Resource
22
- val.solrize
23
- else
24
- val
25
- end
26
- self.class.create_and_insert_terms(apply_prefix(field_key, opts[:name]), val, field_info[:behaviors], solr_doc)
27
- end
28
- end
29
- end
30
- end
31
-
32
- # Gives the primary solr name for a column. If there is more than one indexer on the field definition, it gives the first
33
- def primary_solr_name(field, file_path)
34
- config = self.class.config_for_term_or_uri(field)
35
- return nil unless config # punt on index names for deep nodes!
36
- if behaviors = config.behaviors
37
- behaviors.each do |behavior|
38
- result = ActiveFedora::SolrQueryBuilder.solr_name(apply_prefix(field, file_path), behavior, type: config.type)
39
- return result if Solrizer::DefaultDescriptors.send(behavior).evaluate_suffix(:text).stored?
40
- end
41
- raise RuntimeError "no stored fields were found"
42
- end
43
- end
44
-
45
- module ClassMethods
46
- # Gives the datatype for a column.
47
- def type(field)
48
- config_for_term_or_uri(field).type
49
- end
50
- end
51
-
52
- private
53
- # returns a Hash, e.g.: {field => {:values => [], :type => :something, :behaviors => []}, ...}
54
- def fields
55
- field_map = {}.with_indifferent_access
56
-
57
- self.class.properties.each do |name, config|
58
- type = config[:type]
59
- behaviors = config[:behaviors]
60
- next unless type and behaviors
61
- next if config[:class_name] && config[:class_name] < ActiveFedora::Base
62
- resource.query(:subject => rdf_subject, :predicate => config[:predicate]).each_statement do |statement|
63
- field_map[name] ||= {:values => [], :type => type, :behaviors => behaviors}
64
- field_map[name][:values] << statement.object.to_s
65
- end
66
- end
67
- field_map
68
- end
69
- end
70
- end
71
- end