active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -2,14 +2,14 @@ module ActiveFedora
|
|
2
2
|
class Relation
|
3
3
|
|
4
4
|
include FinderMethods, Calculations, SpawnMethods, QueryMethods, Delegation
|
5
|
-
|
5
|
+
|
6
6
|
|
7
7
|
attr_reader :loaded
|
8
8
|
attr_accessor :default_scoped
|
9
9
|
alias :loaded? :loaded
|
10
|
-
|
10
|
+
|
11
11
|
attr_accessor :values, :klass
|
12
|
-
|
12
|
+
|
13
13
|
def initialize(klass, values = {})
|
14
14
|
@klass = klass
|
15
15
|
@loaded = false
|
@@ -56,7 +56,7 @@ module ActiveFedora
|
|
56
56
|
args[:rows] = limit_value if limit_value
|
57
57
|
args[:start] = offset_value if offset_value
|
58
58
|
args[:sort] = order_values if order_values
|
59
|
-
|
59
|
+
|
60
60
|
@records = to_enum(:find_each, where_values, args).to_a
|
61
61
|
@loaded = true
|
62
62
|
|
@@ -75,6 +75,7 @@ module ActiveFedora
|
|
75
75
|
|
76
76
|
def inspect
|
77
77
|
to_a.inspect
|
78
|
+
# "<#{self.class} @klass=\"#{@klass}\" @values=\"#{@values.inspect}\">"
|
78
79
|
end
|
79
80
|
|
80
81
|
# Destroys the records matching +conditions+ by instantiating each
|
@@ -119,11 +120,22 @@ module ActiveFedora
|
|
119
120
|
end
|
120
121
|
end
|
121
122
|
|
123
|
+
# Returns a hash of where conditions.
|
124
|
+
#
|
125
|
+
# User.where(name: 'Oscar').where_values_hash
|
126
|
+
# # => {name: "Oscar"}
|
127
|
+
def where_values_hash
|
128
|
+
{}
|
129
|
+
end
|
130
|
+
|
131
|
+
def scope_for_create
|
132
|
+
@scope_for_create ||= where_values_hash.merge(create_with_value)
|
133
|
+
end
|
122
134
|
|
123
135
|
private
|
124
136
|
|
125
137
|
VALID_FIND_OPTIONS = [:order, :limit, :start, :conditions, :cast]
|
126
|
-
|
138
|
+
|
127
139
|
def apply_finder_options(options)
|
128
140
|
relation = clone
|
129
141
|
return relation unless options
|
@@ -139,6 +151,6 @@ module ActiveFedora
|
|
139
151
|
relation = relation.where(finders[:conditions]) if options.has_key?(:conditions)
|
140
152
|
relation
|
141
153
|
end
|
142
|
-
|
154
|
+
|
143
155
|
end
|
144
156
|
end
|
@@ -31,7 +31,7 @@ module ActiveFedora
|
|
31
31
|
# Returns an Array of objects of the Class that +find+ is being
|
32
32
|
# called on
|
33
33
|
#
|
34
|
-
# @param[String,Hash] args either
|
34
|
+
# @param[String,Hash] args either an id or a hash of conditions
|
35
35
|
# @option args [Integer] :rows when :all is passed, the maximum number of rows to load from solr
|
36
36
|
# @option args [Boolean] :cast when true, examine the model and cast it to the first known cModel
|
37
37
|
def find(*args)
|
@@ -52,17 +52,37 @@ module ActiveFedora
|
|
52
52
|
|
53
53
|
if options.present?
|
54
54
|
options = args.first unless args.empty?
|
55
|
+
Deprecation.warn(ActiveFedora::Base, "Calling .find with a hash has been deprecated and will not be allowed in active-fedora 10.0. Use .where instead")
|
55
56
|
options = {conditions: options}
|
56
57
|
apply_finder_options(options)
|
57
58
|
else
|
58
|
-
raise ArgumentError, "#{self}.find() expects
|
59
|
+
raise ArgumentError, "#{self}.find() expects an id. You provided `#{args.inspect}'" unless args.is_a? Array
|
59
60
|
find_with_ids(args, cast)
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
|
-
#
|
64
|
+
# Gives a record (or N records if a parameter is supplied) without any implied
|
65
|
+
# order. The order will depend on the database implementation.
|
66
|
+
# If an order is supplied it will be respected.
|
67
|
+
#
|
68
|
+
# Person.take # returns an object fetched by SELECT * FROM people LIMIT 1
|
69
|
+
# Person.take(5) # returns 5 objects fetched by SELECT * FROM people LIMIT 5
|
70
|
+
# Person.where(["name LIKE '%?'", name]).take
|
71
|
+
def take(limit = nil)
|
72
|
+
limit ? limit(limit).to_a : find_take
|
73
|
+
end
|
74
|
+
|
75
|
+
def find_take
|
76
|
+
if loaded?
|
77
|
+
@records.first
|
78
|
+
else
|
79
|
+
@take ||= limit(1).to_a.first
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Returns true if object having the id or matching the conditions exists in the repository
|
64
84
|
# Returns false if param is false (or nil)
|
65
|
-
# @param[ActiveFedora::Base, String, Hash] object,
|
85
|
+
# @param[ActiveFedora::Base, String, Hash] object, id or hash of conditions
|
66
86
|
# @return[boolean]
|
67
87
|
def exists?(conditions)
|
68
88
|
conditions = conditions.id if Base === conditions
|
@@ -71,11 +91,11 @@ module ActiveFedora
|
|
71
91
|
when Hash
|
72
92
|
find_with_conditions(conditions, {rows: 1}).present?
|
73
93
|
when String
|
74
|
-
!!
|
94
|
+
!!find(conditions)
|
75
95
|
else
|
76
96
|
raise ArgumentError, "`conditions' argument must be ActiveFedora::Base, String, or Hash: #{conditions.inspect}"
|
77
97
|
end
|
78
|
-
rescue ActiveFedora::ObjectNotFoundError
|
98
|
+
rescue ActiveFedora::ObjectNotFoundError, Ldp::Gone
|
79
99
|
false
|
80
100
|
end
|
81
101
|
|
@@ -98,15 +118,15 @@ module ActiveFedora
|
|
98
118
|
# Yields the found ActiveFedora::Base object to the passed block
|
99
119
|
#
|
100
120
|
# @param [Hash] conditions the conditions for the solr search to match
|
101
|
-
# @param [Hash] opts
|
102
|
-
# @option opts [Boolean] :cast when true, examine the model and cast it to the first known cModel
|
121
|
+
# @param [Hash] opts
|
122
|
+
# @option opts [Boolean] :cast (true) when true, examine the model and cast it to the first known cModel
|
103
123
|
def find_each( conditions={}, opts={})
|
104
124
|
cast = opts.delete(:cast)
|
105
125
|
find_in_batches(conditions, opts.merge({:fl=>SOLR_DOCUMENT_ID})) do |group|
|
106
126
|
group.each do |hit|
|
107
|
-
begin
|
127
|
+
begin
|
108
128
|
yield(load_from_fedora(hit[SOLR_DOCUMENT_ID], cast))
|
109
|
-
rescue
|
129
|
+
rescue Ldp::Gone
|
110
130
|
ActiveFedora::Base.logger.error "Although #{hit[SOLR_DOCUMENT_ID]} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch." if ActiveFedora::Base.logger
|
111
131
|
end
|
112
132
|
end
|
@@ -119,15 +139,15 @@ module ActiveFedora
|
|
119
139
|
#
|
120
140
|
# Returns a solr result matching the supplied conditions
|
121
141
|
# @param[Hash] conditions solr conditions to match
|
122
|
-
# @param[Hash] options
|
123
|
-
# @option opts [Array] :sort a list of fields to sort by
|
142
|
+
# @param[Hash] options
|
143
|
+
# @option opts [Array] :sort a list of fields to sort by
|
124
144
|
# @option opts [Array] :rows number of rows to return
|
125
145
|
#
|
126
146
|
# @example
|
127
147
|
# Person.find_in_batches('age_t'=>'21', {:batch_size=>50}) do |group|
|
128
148
|
# group.each { |person| puts person['name_t'] }
|
129
149
|
# end
|
130
|
-
|
150
|
+
|
131
151
|
def find_in_batches conditions, opts={}
|
132
152
|
opts[:q] = create_query(conditions)
|
133
153
|
opts[:qt] = @klass.solr_query_handler
|
@@ -144,36 +164,47 @@ module ActiveFedora
|
|
144
164
|
response = ActiveFedora::SolrService.instance.conn.paginate counter, batch_size, "select", :params => opts
|
145
165
|
docs = response["response"]["docs"]
|
146
166
|
yield docs
|
147
|
-
end while docs.has_next?
|
167
|
+
end while docs.has_next?
|
148
168
|
end
|
149
169
|
|
150
|
-
# Retrieve the Fedora object with the given
|
151
|
-
# using #{ActiveFedora::ContentModel.known_models_for} and cast to that class.
|
170
|
+
# Retrieve the Fedora object with the given id, explore the returned object
|
152
171
|
# Raises a ObjectNotFoundError if the object is not found.
|
153
|
-
# @param [String]
|
172
|
+
# @param [String] id of the object to load
|
154
173
|
# @param [Boolean] cast when true, cast the found object to the class of the first known model defined in it's RELS-EXT
|
155
174
|
#
|
156
|
-
# @example because the object hydra:dataset1 asserts it is a Dataset (hasModel info
|
157
|
-
# Book.find_one("hydra:dataset1")
|
158
|
-
def find_one(
|
175
|
+
# @example because the object hydra:dataset1 asserts it is a Dataset (hasModel http://fedora.info/definitions/v4/model#Dataset), return a Dataset object (not a Book).
|
176
|
+
# Book.find_one("hydra:dataset1")
|
177
|
+
def find_one(id, cast=nil)
|
159
178
|
if where_values.empty?
|
160
|
-
load_from_fedora(
|
179
|
+
load_from_fedora(id, cast)
|
161
180
|
else
|
162
|
-
conditions = where_values + [ActiveFedora::SolrService.raw_query(SOLR_DOCUMENT_ID,
|
181
|
+
conditions = where_values + [ActiveFedora::SolrService.raw_query(SOLR_DOCUMENT_ID, id)]
|
163
182
|
query = conditions.join(" AND ".freeze)
|
164
183
|
to_enum(:find_each, query, {}).to_a.first
|
165
184
|
end
|
166
185
|
end
|
167
|
-
|
186
|
+
|
168
187
|
protected
|
169
188
|
|
170
|
-
def load_from_fedora(
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
189
|
+
def load_from_fedora(id, cast)
|
190
|
+
raise ActiveFedora::ObjectNotFoundError if id.empty?
|
191
|
+
resource = LdpResource.new(ActiveFedora.fedora.connection, klass.id_to_uri(id))
|
192
|
+
raise ActiveFedora::ObjectNotFoundError if resource.new?
|
193
|
+
class_to_load(resource, cast).allocate.init_with_resource(resource) # Triggers the find callback
|
194
|
+
end
|
195
|
+
|
196
|
+
def class_to_load(resource, cast)
|
197
|
+
if @klass == ActiveFedora::Base && cast == false
|
198
|
+
ActiveFedora::Base
|
199
|
+
else
|
200
|
+
# The true class may be a subclass of @klass, so always use from_class_uri
|
201
|
+
Model.from_class_uri(has_model_value(resource)) || ActiveFedora::Base
|
175
202
|
end
|
176
|
-
|
203
|
+
end
|
204
|
+
|
205
|
+
# TODO just use has_model
|
206
|
+
def has_model_value(resource)
|
207
|
+
Ldp::Orm.new(resource).value(::RDF::URI.new("http://fedora.info/definitions/v4/rels-ext#hasModel")).first.to_s
|
177
208
|
end
|
178
209
|
|
179
210
|
def find_with_ids(ids, cast)
|
@@ -197,7 +228,6 @@ module ActiveFedora
|
|
197
228
|
ids.map{|id| find_one(id, cast)}
|
198
229
|
end
|
199
230
|
|
200
|
-
|
201
231
|
private
|
202
232
|
|
203
233
|
# Returns a solr query for the supplied conditions
|
@@ -227,7 +257,7 @@ module ActiveFedora
|
|
227
257
|
def condition_to_clauses(key, value)
|
228
258
|
unless value.nil?
|
229
259
|
# if the key is a property name, turn it into a solr field
|
230
|
-
if @klass.
|
260
|
+
if @klass.delegated_attributes.key?(key)
|
231
261
|
# TODO Check to see if `key' is a possible solr field for this class, if it isn't try :searchable instead
|
232
262
|
key = ActiveFedora::SolrService.solr_name(key, :stored_searchable, type: :string)
|
233
263
|
end
|
@@ -235,23 +265,24 @@ module ActiveFedora
|
|
235
265
|
if value.empty?
|
236
266
|
"-#{key}:['' TO *]"
|
237
267
|
elsif value.is_a? Array
|
238
|
-
value.map { |val| "#{key}:#{
|
268
|
+
value.map { |val| "#{key}:#{RSolr.escape(val)}" }
|
239
269
|
else
|
240
|
-
key = SOLR_DOCUMENT_ID if (key === :id || key === :
|
241
|
-
"#{key}:#{
|
270
|
+
key = SOLR_DOCUMENT_ID if (key === :id || key === :id)
|
271
|
+
"#{key}:#{RSolr.escape(value)}"
|
242
272
|
end
|
243
273
|
end
|
244
274
|
end
|
245
275
|
|
246
276
|
# Return the solr clause that queries for this type of class
|
247
277
|
def search_model_clause
|
278
|
+
# The concrete class could could be any subclass of @klass or @klass itself
|
248
279
|
unless @klass == ActiveFedora::Base
|
249
|
-
|
280
|
+
clauses = ([@klass] + @klass.descendants).map do |k|
|
281
|
+
ActiveFedora::SolrService.construct_query_for_rel(has_model: k.to_s)
|
282
|
+
end
|
283
|
+
clauses.size == 1 ? clauses.first : "(#{clauses.join(" OR ")})"
|
250
284
|
end
|
251
285
|
end
|
252
286
|
|
253
|
-
def solr_escape terms
|
254
|
-
RSolr.solr_escape(terms).gsub(/\s+/,"\\ ")
|
255
|
-
end
|
256
287
|
end
|
257
288
|
end
|
@@ -26,7 +26,7 @@ module ActiveFedora
|
|
26
26
|
def order_values=(values)
|
27
27
|
raise ImmutableRelation if @loaded
|
28
28
|
@values[:order] = values
|
29
|
-
end
|
29
|
+
end
|
30
30
|
|
31
31
|
def limit_value
|
32
32
|
@values[:limit]
|
@@ -35,7 +35,7 @@ module ActiveFedora
|
|
35
35
|
def limit_value=(value)
|
36
36
|
raise ImmutableRelation if @loaded
|
37
37
|
@values[:limit] = value
|
38
|
-
end
|
38
|
+
end
|
39
39
|
|
40
40
|
def offset_value
|
41
41
|
@values[:offset]
|
@@ -44,7 +44,7 @@ module ActiveFedora
|
|
44
44
|
def offset_value=(value)
|
45
45
|
raise ImmutableRelation if loaded?
|
46
46
|
@values[:offset] = value
|
47
|
-
end
|
47
|
+
end
|
48
48
|
|
49
49
|
# Limits the returned records to those that match the provided search conditions
|
50
50
|
#
|
@@ -140,5 +140,9 @@ module ActiveFedora
|
|
140
140
|
def select
|
141
141
|
to_a.select { |*block_args| yield(*block_args) }
|
142
142
|
end
|
143
|
+
|
144
|
+
def create_with_value # :nodoc:
|
145
|
+
@values[:create_with] || {}
|
146
|
+
end
|
143
147
|
end
|
144
148
|
end
|
@@ -5,11 +5,11 @@ RSpec::Matchers.define :belong_to_associated_active_fedora_object do |associatio
|
|
5
5
|
if @association_name.nil? || @expected_object.nil?
|
6
6
|
raise(
|
7
7
|
ArgumentError,
|
8
|
-
"subject.
|
8
|
+
"expect(subject).to belong_to_associated_active_fedora_object(<association_name>).with_object(<object>)"
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
-
@subject = subject.class.find(subject.
|
12
|
+
@subject = subject.class.find(subject.id)
|
13
13
|
@actual_object = @subject.send(@association_name)
|
14
14
|
|
15
15
|
@expected_object == @actual_object
|
@@ -19,15 +19,15 @@ RSpec::Matchers.define :belong_to_associated_active_fedora_object do |associatio
|
|
19
19
|
|
20
20
|
|
21
21
|
description do
|
22
|
-
"#{@subject.class}
|
22
|
+
"#{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} matches ActiveFedora"
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
"expected #{@subject.class}
|
25
|
+
failure_message do |text|
|
26
|
+
"expected #{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} to match"
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
"expected #{@subject.class}
|
29
|
+
failure_message_when_negated do |text|
|
30
|
+
"expected #{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} to NOT match"
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -6,11 +6,11 @@ RSpec::Matchers.define :have_many_associated_active_fedora_objects do |associati
|
|
6
6
|
if @association_name.nil? || !@expected_objects.respond_to?(:count)
|
7
7
|
raise(
|
8
8
|
ArgumentError,
|
9
|
-
"subject.
|
9
|
+
"expect(subject).to have_many_associated_active_fedora_objects(<association_name>).with_objects(<objects[]>)"
|
10
10
|
)
|
11
11
|
end
|
12
12
|
|
13
|
-
@subject = subject.class.find(subject.
|
13
|
+
@subject = subject.class.find(subject.id)
|
14
14
|
@actual_objects = @subject.send(@association_name)
|
15
15
|
|
16
16
|
if @expected_objects
|
@@ -19,7 +19,7 @@ RSpec::Matchers.define :have_many_associated_active_fedora_objects do |associati
|
|
19
19
|
if actual_count != expected_count
|
20
20
|
raise(
|
21
21
|
RSpec::Expectations::ExpectationNotMetError,
|
22
|
-
"#{@subject.class}
|
22
|
+
"#{@subject.class} ID=#{@subject.id} relationship: #{@association_name.inspect} count <Expected Count: #{expected_count}> <Actual: #{actual_count}>"
|
23
23
|
)
|
24
24
|
end
|
25
25
|
intersection = @actual_objects & @expected_objects
|
@@ -31,15 +31,15 @@ RSpec::Matchers.define :have_many_associated_active_fedora_objects do |associati
|
|
31
31
|
|
32
32
|
|
33
33
|
description do
|
34
|
-
"#{@subject.class}
|
34
|
+
"#{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} matches ActiveFedora"
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
|
-
"expected #{@subject.class}
|
37
|
+
failure_message do |text|
|
38
|
+
"expected #{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} to match"
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
"expected #{@subject.class}
|
41
|
+
failure_message_when_negated do |text|
|
42
|
+
"expected #{@subject.class} ID=#{@subject.id} association: #{@association_name.inspect} to NOT match"
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
@@ -6,10 +6,10 @@ RSpec::Matchers.define :have_predicate do |predicate|
|
|
6
6
|
if @predicate.nil? || !@expected_objects.respond_to?(:count)
|
7
7
|
raise(
|
8
8
|
ArgumentError,
|
9
|
-
"subject.
|
9
|
+
"expect(subject).to have_predicate(<predicate>).with_objects(<objects[]>)"
|
10
10
|
)
|
11
11
|
end
|
12
|
-
@subject = subject.class.find(subject.
|
12
|
+
@subject = subject.class.find(subject.id)
|
13
13
|
@actual_objects = @subject.relationships(predicate)
|
14
14
|
|
15
15
|
if @expected_objects
|
@@ -18,12 +18,10 @@ RSpec::Matchers.define :have_predicate do |predicate|
|
|
18
18
|
if actual_count != expected_count
|
19
19
|
raise(
|
20
20
|
RSpec::Expectations::ExpectationNotMetError,
|
21
|
-
"#{@subject.class}
|
21
|
+
"#{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} count <Expected Count: #{expected_count}> <Actual: #{actual_count}>"
|
22
22
|
)
|
23
23
|
end
|
24
|
-
intersection = @actual_objects
|
25
|
-
internal_uri = ao.respond_to?(:internal_uri) ? ao.internal_uri : ao
|
26
|
-
end & @expected_objects
|
24
|
+
intersection = @actual_objects & @expected_objects
|
27
25
|
|
28
26
|
intersection.count == @expected_objects.count
|
29
27
|
end
|
@@ -33,15 +31,15 @@ RSpec::Matchers.define :have_predicate do |predicate|
|
|
33
31
|
|
34
32
|
|
35
33
|
description do
|
36
|
-
"#{@subject.class}
|
34
|
+
"#{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} matches Fedora"
|
37
35
|
end
|
38
36
|
|
39
|
-
|
40
|
-
"expected #{@subject.class}
|
37
|
+
failure_message do |text|
|
38
|
+
"expected #{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} to match"
|
41
39
|
end
|
42
40
|
|
43
|
-
|
44
|
-
"expected #{@subject.class}
|
41
|
+
failure_message_when_negated do |text|
|
42
|
+
"expected #{@subject.class} ID=#{@subject.id} relationship: #{@predicate.inspect} to NOT match"
|
45
43
|
end
|
46
44
|
|
47
45
|
end
|
@@ -27,15 +27,15 @@ module ActiveFedora
|
|
27
27
|
|
28
28
|
# This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
|
29
29
|
# each field will have the 2 magic methods:
|
30
|
-
# name=(arg)
|
31
|
-
# name
|
30
|
+
# name=(arg)
|
31
|
+
# name
|
32
32
|
#
|
33
33
|
#
|
34
34
|
# 'datatype' is a datatype, currently :string, :integer and :date are supported.
|
35
35
|
#
|
36
36
|
# opts is an options hash, which will affect the generation of the xml representation of this datastream.
|
37
37
|
#
|
38
|
-
# Currently supported modifiers:
|
38
|
+
# Currently supported modifiers:
|
39
39
|
# For +SimpleDatastream+:
|
40
40
|
# :element_attrs =>{:foo=>:bar} - hash of xml element attributes
|
41
41
|
# :xml_node => :nodename - The xml node to be used to represent this object (in dcterms namespace)
|
@@ -45,8 +45,8 @@ module ActiveFedora
|
|
45
45
|
#
|
46
46
|
#There is quite a good example of this class in use in spec/examples/oral_history.rb
|
47
47
|
#
|
48
|
-
#!! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
|
49
|
-
#you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
|
48
|
+
#!! Careful: If you declare two fields that correspond to the same xml node without any qualifiers to differentiate them,
|
49
|
+
#you will end up replicating the values in the underlying datastream, resulting in mysterious dubling, quadrupling, etc.
|
50
50
|
#whenever you edit the field's values.
|
51
51
|
def field(name, datatype=:string, opts={})
|
52
52
|
fields ||= {}
|
@@ -59,9 +59,9 @@ module ActiveFedora
|
|
59
59
|
self.class.terminology.add_term(term)
|
60
60
|
term.generate_xpath_queries!
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
def update_indexed_attributes(params={}, opts={})
|
66
66
|
raise "can't modify frozen #{self.class}" if frozen?
|
67
67
|
# if the params are just keys, not an array, make then into an array.
|
@@ -75,20 +75,25 @@ module ActiveFedora
|
|
75
75
|
end
|
76
76
|
super(new_params, opts)
|
77
77
|
end
|
78
|
+
|
78
79
|
|
79
80
|
def self.xml_template
|
80
|
-
|
81
|
+
Nokogiri::XML::Document.parse("<fields/>")
|
81
82
|
end
|
82
83
|
|
83
|
-
def to_solr(solr_doc = Hash.new) # :nodoc:
|
84
|
+
def to_solr(solr_doc = Hash.new, opts = {}) # :nodoc:
|
84
85
|
@fields.each do |field_key, field_info|
|
85
86
|
next if field_key == :location ## FIXME HYDRA-825
|
86
|
-
|
87
|
-
|
88
|
-
::
|
87
|
+
things = send(field_key)
|
88
|
+
if things
|
89
|
+
field_symbol = ActiveFedora::SolrService.solr_name(field_key, type: field_info[:type])
|
90
|
+
things.val.each do |val|
|
91
|
+
::Solrizer::Extractor.insert_solr_field_value(solr_doc, field_symbol, val.to_s )
|
92
|
+
end
|
89
93
|
end
|
90
94
|
end
|
91
|
-
solr_doc
|
95
|
+
return solr_doc
|
92
96
|
end
|
97
|
+
|
93
98
|
end
|
94
99
|
end
|