Skip to content

Commit

Permalink
Merge pull request #771 from projecthydra/revert_feature
Browse files Browse the repository at this point in the history
Revert "Move the indexing logic to the model."
  • Loading branch information
awead committed Apr 17, 2015
2 parents bc75c1e + cabb905 commit d02dd24
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 226 deletions.
10 changes: 1 addition & 9 deletions lib/active_fedora/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,14 @@ def delegated_attributes= val
@delegated_attributes = val
end

def has_attributes(*fields, &block)
def has_attributes(*fields)
options = fields.pop
datastream = options.delete(:datastream).to_s
raise ArgumentError, "You must provide a datastream to has_attributes" if datastream.blank?
define_attribute_methods fields
fields.each do |f|
create_attribute_reader(f, datastream, options)
create_attribute_setter(f, datastream, options)
add_attribute_indexing_config(f, &block) if block_given?
end
end

Expand All @@ -178,17 +177,10 @@ def property name, properties={}, &block
raise ArgumentError, "#{name} is a keyword and not an acceptable property name." if protected_property_name? name
reflection = ActiveFedora::Attributes::PropertyBuilder.build(self, name, properties, &block)
ActiveTriples::Reflection.add_reflection self, name, reflection

add_attribute_indexing_config(name, &block) if block_given?
end

private

def add_attribute_indexing_config(name, &block)
# TODO the hash can be initalized to return on of these
index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new &block
end

def warn_duplicate_predicates new_name, new_properties
new_predicate = new_properties[:predicate]
self.properties.select{|k, existing| existing.predicate == new_predicate}.each do |key, value|
Expand Down
1 change: 0 additions & 1 deletion lib/active_fedora/attributes/property_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def #{name}=(value)
end

def build(&block)
#TODO remove this block stuff
NodeConfig.new(name, options[:predicate], options.except(:predicate)) do |config|
config.with_index(&block) if block_given?
end
Expand Down
14 changes: 0 additions & 14 deletions lib/active_fedora/indexing.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module ActiveFedora
module Indexing
extend ActiveSupport::Concern
extend ActiveSupport::Autoload

eager_autoload do
autoload :Map
end

# Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
# @param [Hash] solr_doc (optional) Hash to insert the fields into
Expand Down Expand Up @@ -56,15 +51,6 @@ def update_record(options = {})

module ClassMethods

# @return ActiveFedora::Indexing::Map
def index_config
@index_config ||= if superclass.respond_to?(:index_config)
superclass.index_config.deep_dup
else
ActiveFedora::Indexing::Map.new
end
end

def indexer
IndexingService
end
Expand Down
46 changes: 0 additions & 46 deletions lib/active_fedora/indexing/map.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/active_fedora/rdf/datastream_indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ module ClassMethods
def indexer
ActiveFedora::RDF::IndexingService
end

def index_config
@index_config ||= ActiveFedora::Indexing::Map.new
end
end

protected
Expand Down
28 changes: 10 additions & 18 deletions lib/active_fedora/rdf/indexing_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def generate_solr_document(prefix_method = nil)

def add_assertions(prefix_method, solr_doc = {})
fields.each do |field_key, field_info|
values = resource.get_values(field_key)
solr_field_key = solr_document_field_name(field_key, prefix_method)
Array(field_info[:values]).each do |val|
Array(values).each do |val|
append_to_solr_doc(solr_doc, solr_field_key, field_info, val)
end
end
Expand Down Expand Up @@ -69,31 +70,22 @@ def properties
object.class.properties
end

def index_config
object.class.index_config
end

# returns a Hash, e.g.: {field => { values: [], type: :something, behaviors: [] }, ...}
def fields
field_map = {}.with_indifferent_access

index_config.each do |name, index_field_config|
type = index_field_config.data_type
behaviors = index_field_config.behaviors
properties.each do |name, config|
type = config[:type]
behaviors = config[:behaviors]
next unless type and behaviors
next if kind_of_af_base?(name)
field_map[name] = { values: find_values(name), type: type, behaviors: behaviors}
next if config[:class_name] && config[:class_name] < ActiveFedora::Base
resource.query(subject: object.rdf_subject, predicate: config[:predicate]).each_statement do |statement|
field_map[name] ||= { values: [], type: type, behaviors: behaviors}
field_map[name][:values] << statement.object.to_s
end
end
field_map
end

def kind_of_af_base?(name)
config = properties[name.to_s]
config && config[:class_name] && config[:class_name] < ActiveFedora::Base
end

def find_values(name)
object.send(name) || []
end
end
end
11 changes: 0 additions & 11 deletions lib/active_fedora/rdf/rdf_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ def rdf_subject &block
@subject_block ||= lambda { |ds| parent_uri(ds) }
end

def property(name, *args, &block)
super
add_attribute_indexing_config(name, &block) if block_given?
end

def add_attribute_indexing_config(name, &block)
Deprecation.warn(RDFDatastream, "Adding indexing to datastreams is deprecated")
# TODO the hash can be initalized to return on of these
index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new &block
end

# Trim the last segment off the URI to get the parents uri
def parent_uri(ds)
m = /^(.*)\/[^\/]*$/.match(ds.uri)
Expand Down
43 changes: 1 addition & 42 deletions spec/integration/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class TitledObject < ActiveFedora::Base
end
class RdfObject < ActiveFedora::Base
contains 'foo', class_name: 'PropertiesDatastream'
has_attributes :depositor, datastream: :foo, multiple: false do |index|
index.as :stored_searchable
end
has_attributes :depositor, datastream: :foo, multiple: false
has_attributes :wrangler, datastream: :foo, multiple: true
property :resource_type, predicate: ::RDF::DC.type do |index|
index.as :stored_searchable, :facetable
Expand All @@ -33,45 +31,6 @@ class RdfObject < ActiveFedora::Base
Object.send(:remove_const, :PropertiesDatastream)
end

describe "#index_config" do
context "on a class with properties" do
subject { RdfObject.index_config }
it "should have configuration " do
expect(subject[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
expect(subject[:depositor].behaviors).to eq [:stored_searchable]
end
end

context "when a class inherits properties" do
before do
class InheritedObject < RdfObject
end
end

after do
Object.send(:remove_const, :InheritedObject)
end

subject { InheritedObject.index_config }

it "should have configuration " do
expect(subject[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
expect(subject[:depositor].behaviors).to eq [:stored_searchable]
end

context "when the inherited config is modifed" do
before do
InheritedObject.index_config[:resource_type].behaviors.delete(:stored_searchable)
end
subject { RdfObject.index_config }

it "the parent config is unchanged" do
expect(subject[:resource_type].behaviors).to eq [:stored_searchable, :facetable]
end
end
end
end

context "with a simple datastream" do
describe "save" do
subject do
Expand Down
14 changes: 6 additions & 8 deletions spec/integration/field_to_solr_name_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
before do
class TestOne < ActiveFedora::Base
class MyMetadata < ActiveFedora::NtriplesRDFDatastream
Deprecation.silence(ActiveFedora::RDFDatastream) do
property :title, predicate: ::RDF::DC.title do |index|
index.as :stored_searchable
end
property :date_uploaded, predicate: ::RDF::DC.dateSubmitted do |index|
index.type :date
index.as :stored_searchable, :sortable
end
property :title, predicate: ::RDF::DC.title do |index|
index.as :stored_searchable
end
property :date_uploaded, predicate: ::RDF::DC.dateSubmitted do |index|
index.type :date
index.as :stored_searchable, :sortable
end
end
has_metadata 'descMetadata', type: MyMetadata
Expand Down
6 changes: 2 additions & 4 deletions spec/integration/json_serialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ class DummySubnode < ActiveTriples::Resource
end

class DummyResource < ActiveFedora::RDFDatastream
Deprecation.silence(ActiveFedora::RDFDatastream) do
property :license, predicate: ::RDF::DC[:license], class_name: DummySubnode do |index|
index.as :searchable, :displayable
end
property :license, predicate: ::RDF::DC[:license], class_name: DummySubnode do |index|
index.as :searchable, :displayable
end
def serialization_format
:ntriples
Expand Down
30 changes: 14 additions & 16 deletions spec/integration/ntriples_datastream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ class FileVocabulary < RDF::Vocabulary("http://downlode.org/Code/RDF/File_Proper
property :size
end

Deprecation.silence(ActiveFedora::RDFDatastream) do
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
property :title, predicate: ::RDF::DC.title do |index|
index.as :stored_searchable, :facetable
end
property :date_uploaded, predicate: ::RDF::DC.dateSubmitted do |index|
index.type :date
index.as :stored_searchable, :sortable
end
property :filesize, predicate: FileVocabulary.size do |index|
index.type :integer
index.as :stored_sortable
end
property :part, predicate: ::RDF::DC.hasPart
property :based_near, predicate: ::RDF::FOAF.based_near
property :related_url, predicate: ::RDF::RDFS.seeAlso
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
property :title, predicate: ::RDF::DC.title do |index|
index.as :stored_searchable, :facetable
end
property :date_uploaded, predicate: ::RDF::DC.dateSubmitted do |index|
index.type :date
index.as :stored_searchable, :sortable
end
property :filesize, predicate: FileVocabulary.size do |index|
index.type :integer
index.as :stored_sortable
end
property :part, predicate: ::RDF::DC.hasPart
property :based_near, predicate: ::RDF::FOAF.based_near
property :related_url, predicate: ::RDF::RDFS.seeAlso
end

class RdfTest < ActiveFedora::Base
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/base_active_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BarHistory < ActiveFedora::Base
end
has_metadata :type=>ActiveFedora::SimpleDatastream, :name=>"withText2" do |m|
m.field "fubar", :text
end
end

has_metadata :type=>BarStream, :name=>"xmlish"
has_attributes :fubar, datastream: 'withText', multiple: false
Expand Down
40 changes: 19 additions & 21 deletions spec/unit/ntriples_datastream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,26 @@ class MyDatastream < ActiveFedora::NtriplesRDFDatastream

describe "solr integration" do
before(:all) do
Deprecation.silence(ActiveFedora::RDFDatastream) do
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
property :created, predicate: ::RDF::DC.created do |index|
index.as :sortable, :displayable
index.type :date
end
property :title, predicate: ::RDF::DC.title do |index|
index.as :stored_searchable, :sortable
index.type :text
end
property :publisher, predicate: ::RDF::DC.publisher do |index|
index.as :facetable, :sortable, :stored_searchable
end
property :based_near, predicate: ::RDF::FOAF.based_near do |index|
index.as :facetable, :stored_searchable
index.type :text
end
property :related_url, predicate: ::RDF::RDFS.seeAlso do |index|
index.as :stored_searchable
end
property :rights, predicate: ::RDF::DC.rights
class MyDatastream < ActiveFedora::NtriplesRDFDatastream
property :created, predicate: ::RDF::DC.created do |index|
index.as :sortable, :displayable
index.type :date
end
property :title, predicate: ::RDF::DC.title do |index|
index.as :stored_searchable, :sortable
index.type :text
end
property :publisher, predicate: ::RDF::DC.publisher do |index|
index.as :facetable, :sortable, :stored_searchable
end
property :based_near, predicate: ::RDF::FOAF.based_near do |index|
index.as :facetable, :stored_searchable
index.type :text
end
property :related_url, predicate: ::RDF::RDFS.seeAlso do |index|
index.as :stored_searchable
end
property :rights, predicate: ::RDF::DC.rights
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/query_result_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe ActiveFedora::QueryResultBuilder do
describe QueryResultBuilder do
describe "reify solr results" do
before(:all) do
class AudioRecord
Expand Down
Loading

0 comments on commit d02dd24

Please sign in to comment.