active-fedora 9.0.8 → 9.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/History.txt +0 -57
  3. data/README.md +38 -24
  4. data/active-fedora.gemspec +1 -1
  5. data/lib/active_fedora.rb +1 -0
  6. data/lib/active_fedora/associations.rb +1 -1
  7. data/lib/active_fedora/attached_files.rb +1 -1
  8. data/lib/active_fedora/attributes.rb +36 -10
  9. data/lib/active_fedora/attributes/property_builder.rb +1 -0
  10. data/lib/active_fedora/clean_connection.rb +40 -0
  11. data/lib/active_fedora/fedora.rb +4 -0
  12. data/lib/active_fedora/file.rb +5 -5
  13. data/lib/active_fedora/indexing.rb +14 -0
  14. data/lib/active_fedora/indexing/map.rb +46 -0
  15. data/lib/active_fedora/persistence.rb +4 -4
  16. data/lib/active_fedora/rdf/datastream_indexing.rb +4 -0
  17. data/lib/active_fedora/rdf/fcrepo4.rb +1 -0
  18. data/lib/active_fedora/rdf/indexing_service.rb +18 -11
  19. data/lib/active_fedora/rdf/ldp.rb +3 -0
  20. data/lib/active_fedora/rdf/rdf_datastream.rb +12 -1
  21. data/lib/active_fedora/solr_query_builder.rb +1 -1
  22. data/lib/active_fedora/solr_service.rb +1 -1
  23. data/lib/active_fedora/version.rb +1 -1
  24. data/spec/integration/attributes_spec.rb +49 -3
  25. data/spec/integration/clean_connection_spec.rb +21 -0
  26. data/spec/integration/field_to_solr_name_spec.rb +11 -7
  27. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +30 -26
  28. data/spec/integration/has_many_associations_spec.rb +6 -2
  29. data/spec/integration/json_serialization_spec.rb +11 -5
  30. data/spec/integration/nested_attribute_spec.rb +3 -1
  31. data/spec/integration/ntriples_datastream_spec.rb +23 -17
  32. data/spec/integration/persistence_spec.rb +3 -1
  33. data/spec/integration/relation_delegation_spec.rb +3 -1
  34. data/spec/integration/scoped_query_spec.rb +3 -1
  35. data/spec/integration/solr_instance_loader_spec.rb +4 -2
  36. data/spec/unit/attributes_spec.rb +52 -12
  37. data/spec/unit/base_active_model_spec.rb +5 -3
  38. data/spec/unit/base_spec.rb +4 -2
  39. data/spec/unit/callback_spec.rb +4 -2
  40. data/spec/unit/core_spec.rb +4 -2
  41. data/spec/unit/ntriples_datastream_spec.rb +24 -20
  42. data/spec/unit/query_result_builder_spec.rb +1 -1
  43. data/spec/unit/rdf/indexing_service_spec.rb +19 -17
  44. data/spec/unit/rdf_resource_datastream_spec.rb +14 -10
  45. data/spec/unit/simple_datastream_spec.rb +3 -1
  46. data/spec/unit/solr_query_builder_spec.rb +1 -1
  47. data/spec/unit/validations_spec.rb +4 -2
  48. metadata +12 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ebf611de1fa3721bc0d53f15e6210ced8509072da4f1406f818e2f14c5f11be2
4
- data.tar.gz: 1f6729e4bce4f1b03ba5ba2864c4dbe84ae454932221de98fe4357b8e80e69e4
2
+ SHA1:
3
+ metadata.gz: 1867e34e4a11cea022a7d127a3c4342b9b79d8e2
4
+ data.tar.gz: ba76e2cab3c5a808d2a7962cd5abd3fa6c1c5a1d
5
5
  SHA512:
6
- metadata.gz: f5ba1bc7bcb326f435f1ed88cad1e1a7b68c04b122472379430bf320a634e67e3da72c13c424dda5ba1f9d2673aec820a74d9b7adffb60bd9c23498f89ed7b52
7
- data.tar.gz: 2e06a0593ec85862f1995277e7a530f05bff3f31e30ed80a4719c04beb8807c28060ec275fa2d833c118b83ad22fb812c5a07d848823bbfc9d90bb8693683fd9
6
+ metadata.gz: 0b3caee0805b7b284a6894641cd57e1e409ada72da6ec11e718d4290b20b03ab1715accca3c08355bf49202ae69598e2b78e1cc7821f3437b8d138f29be05516
7
+ data.tar.gz: 1b3fa97271e54470676c3f896b5cd343a17e68690cb72125ec5047100f8d659933ca34a5fca34a34d7ce736b4962b9bbf66d41e84f9486bbb7af38accfce229f
@@ -1,60 +1,3 @@
1
- v9.0.8
2
-
3
- 2015-04-15: Revert "Move the indexing logic to the model. Fixes #736"
4
- [Justin Coyne] (cabb9057)
5
-
6
- 2015-04-15: Fix deleting from a HABTM when the inverse_of is a
7
- has_many. Fixes #763 [Justin Coyne] (b1e67fb1)
8
-
9
- 2015-04-15: Remove a spec that is a duplicate of
10
- integration/collection_association_spec.rb:92 [Justin Coyne]
11
- (bdafd50d)
12
-
13
- 2015-04-15: Leverage the code in AssociationRelation to find the
14
- inverse. Fixes #760 [Justin Coyne] (c764ea70)
15
-
16
- 2015-04-15: Make #translate_id_to_uri/uri_to_id reliable. [Trey
17
- Terrell] (80a4e3fd)
18
-
19
- 2015-04-15: Find best model match in case of inheritance [Stuart
20
- Kenny] (481a9cd4)
21
-
22
- 2015-04-15: Requires 'deprecation' for ActiveFedora::File [Andrew
23
- Myers] (14be5cf6)
24
-
25
- 2015-04-07: The indexing hints should be inheritable [Justin Coyne]
26
- (c8d41b91)
27
-
28
- v9.0.7
29
- 2015-04-06: Only set/save the inverse on a HABTM if the inverse is also HABTM
30
- previously we were getting: [Justin Coyne]
31
-
32
- 2015-04-06: Derive a foreign_key ending with `_ids` if the inverse is a
33
- collection [Justin Coyne]
34
-
35
- 2015-04-06: Find inverse relations when class_names have modules [Justin Coyne]
36
-
37
- 2015-04-06: Raise an error when the inverse relationship can not be found.
38
- Previously a "SystemStackError: Stack too deep" was encountered in this
39
- situation [Justin Coyne]
40
-
41
- 2015-04-02: Add a mechanism to set rdf_label on the ActiveTriple resource
42
- [Justin Coyne]
43
-
44
- 2015-04-03: Refactor has_and_belongs_to_many_associations_spec [Justin Coyne]
45
-
46
- 2015-04-03: Remove unused sample classes [Justin Coyne]
47
-
48
- 2015-04-02: Sort versions as dates not as strings [Justin Coyne]
49
-
50
- 2015-04-01: Prevents an object from being loaded to the incorrect class. For
51
- example, when loading a batch object it should be loaded into a Batch (and not a
52
- File for example.) [Justin Coyne]
53
-
54
- 2015-03-27: Move the indexing logic to the model. Fixes #736 You should now add
55
- indexing hints to has_attributes by passing a block similar to how you do it
56
- with rdf properties. e.g.: [Justin Coyne]
57
-
58
1
  v9.0.6
59
2
  2015-03-26: Setting type should not wipe out properties. Fixes #737 [Justin Coyne]
60
3
 
data/README.md CHANGED
@@ -23,21 +23,24 @@ Installation
23
23
 
24
24
  The gem is hosted on rubygems.
25
25
 
26
- gem install active-fedora
26
+ ```bash
27
+ gem install active-fedora
28
+ ```
27
29
 
28
30
  Getting Started
29
31
  ---------------
30
32
 
31
33
  The [Dive into Hydra](https://github.com/projecthydra/hydra/wiki/Dive-into-Hydra)
32
- gives you a brief tour through ActiveFedora’s features on the command
33
- line.
34
+ gives you a brief tour through ActiveFedora’s features on the command line.
34
35
 
35
36
  Generators
36
37
  ----------
37
38
 
38
39
  You can generate a model inheriting from ActiveFedora::Base.
39
40
 
40
- rails generate active_fedora:model Book
41
+ ```bash
42
+ rails generate active_fedora:model Book
43
+ ```
41
44
 
42
45
  Testing (this Gem)
43
46
  ------------------
@@ -46,25 +49,30 @@ In order to run the RSpec tests, you need to have a copy of the
46
49
  ActiveFedora source code, and then run bundle install in the source
47
50
  directory. Testing requires hydra-jetty, which contains version for
48
51
  Fedora and Solr. Setting up and maintaining hydra-jetty for the purposes
49
- of testing this gem is all accomplished via
52
+ of testing this gem is all accomplished via:
50
53
 
51
- git clone https://github.com/projecthydra/active_fedora.git
52
- cd /wherever/active_fedora/is
53
- bundle install
54
+ ```bash
55
+ git clone https://github.com/projecthydra/active_fedora.git
56
+ cd active_fedora # or whatever directory your clone is in
57
+ bundle install
58
+ ```
54
59
 
55
60
  ### Using the continuous integration server
56
61
 
57
62
  You can test ActiveFedora using the same process as our continuous
58
- integration server. To do that, unzip a copy\
59
- of hydra-jetty first. This includes copies of Fedora and Solr which are
63
+ integration server. To do that, unzip a copy of hydra-jetty first. This includes copies of Fedora and Solr which are
60
64
  used during the testing process.
61
65
 
62
- rake jetty:unzip
66
+ ```bash
67
+ rake jetty:unzip
68
+ ```
63
69
 
64
70
  Once hydra-jetty is unzipped, the ci rake task will spin up jetty,
65
71
  import the fixtures, and run the tests for you.
66
72
 
67
- rake active_fedora:ci
73
+ ```bash
74
+ rake active_fedora:ci
75
+ ```
68
76
 
69
77
  ### Testing Manually
70
78
 
@@ -73,30 +81,36 @@ If you want to run the tests manually, follow these instructions.
73
81
  You need to have a copy of hydra-jetty running. To do this, download a
74
82
  working copy of
75
83
  [hydra-jetty](https://github.com/projecthydra/hydra-jetty), cd into its
76
- root and run
84
+ root and run:
77
85
 
78
- java -jar start.jar
86
+ ```bash
87
+ java -jar start.jar
88
+ ```
79
89
 
80
- Now you’re ready to run the tests. In the directory where active\_fedora
81
- is installed, run
90
+ Now you’re ready to run the tests. In the directory where active_fedora
91
+ is installed, run:
82
92
 
83
- rake spec
93
+ ```bash
94
+ rake spec
95
+ ```
84
96
 
85
97
  Predicate Mappings
86
98
  ------------------
87
99
 
88
100
  ActiveFedora versions 2.2.1 and higher provides specialized control over
89
101
  the predicate mappings used by SemanticNode. In order to provide your
90
- own mappings, \
91
- you must supply a predicate\_mappings.yml in the same format as the
92
- config/predicate\_mappings.yml file shipped with the ActiveFedora gem.
93
- Place the file in the same directory\
94
- as your fedora.yml file and use the current method of initializing
102
+ own mappings,
103
+ you must supply a `predicate_mappings.yml` in the same format as the
104
+ `config/predicate_mappings.yml` file shipped with the ActiveFedora gem.
105
+ Place the file in the same directory
106
+ as your `fedora.yml` file and use the current method of initializing
95
107
  ActiveFedora:
96
108
 
97
- ActiveFedora.init("/path/to/my/config/fedora.yml")
109
+ ```ruby
110
+ ActiveFedora.init("/path/to/my/config/fedora.yml")
111
+ ```
98
112
 
99
- If no predicate\_mappings.yml file is found, ActiveFedora will use the
113
+ If no `predicate_mappings.yml` file is found, ActiveFedora will use the
100
114
  default mappings.
101
115
 
102
116
  Acknowledgements
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency "rdf-rdfxml", '~> 1.1.0'
23
23
  s.add_dependency "linkeddata"
24
24
  s.add_dependency "deprecation"
25
- s.add_dependency "ldp", '~> 0.2.1'
25
+ s.add_dependency "ldp", '~> 0.3.0'
26
26
  s.add_dependency "rdf-ldp"
27
27
 
28
28
  s.add_development_dependency "rdoc"
@@ -49,6 +49,7 @@ module ActiveFedora #:nodoc:
49
49
  autoload :CachingConnection
50
50
  autoload :Callbacks
51
51
  autoload :ChangeSet
52
+ autoload :CleanConnection
52
53
  autoload :Config
53
54
  autoload :Core
54
55
  autoload_under 'core' do
@@ -86,7 +86,7 @@ module ActiveFedora
86
86
  # Note that this method doesn't actually execute the block, but stores it, to be executed
87
87
  # by any the implementation of the datastream(specified as :class_name)
88
88
  #
89
- # @param [String] :name the handle to refer to this child as
89
+ # @param [String] name the handle to refer to this child as
90
90
  # @param [Hash] options
91
91
  # @option options [Class] :class_name The class that will represent this child, should extend ``ActiveFedora::File''
92
92
  # @option options [String] :url
@@ -86,7 +86,7 @@ module ActiveFedora
86
86
  # Attach the given stream/string to object
87
87
  #
88
88
  # @param [IO, String] file the file to add
89
- # @param [Hash] opts options: :dsid, :prefix, :mime_type
89
+ # @param [Hash] args options: :dsid, :prefix, :mime_type
90
90
  # @option opts [String] :path The file path
91
91
  # @option opts [String] :prefix The path prefix (for auto-generated path)
92
92
  # @option opts [String] :mime_type The Mime-Type of the file
@@ -1,7 +1,10 @@
1
1
  require 'active_model/forbidden_attributes_protection'
2
+ require 'deprecation'
2
3
  module ActiveFedora
3
4
  module Attributes
4
5
  extend ActiveSupport::Concern
6
+ extend Deprecation
7
+ self.deprecation_horizon = 'ActiveFedora 10.0'
5
8
  include ActiveModel::Dirty
6
9
  include ActiveModel::ForbiddenAttributesProtection
7
10
 
@@ -144,15 +147,9 @@ module ActiveFedora
144
147
  @delegated_attributes = val
145
148
  end
146
149
 
147
- def has_attributes(*fields)
148
- options = fields.pop
149
- datastream = options.delete(:datastream).to_s
150
- raise ArgumentError, "You must provide a datastream to has_attributes" if datastream.blank?
151
- define_attribute_methods fields
152
- fields.each do |f|
153
- create_attribute_reader(f, datastream, options)
154
- create_attribute_setter(f, datastream, options)
155
- end
150
+ def has_attributes(*fields, &block)
151
+ Deprecation.warn(Attributes, "has_attributes is deprecated and will be removed in ActiveFedora 10.0. Use property instead")
152
+ define_delegated_accessor(*fields, &block)
156
153
  end
157
154
 
158
155
  # Reveal if the attribute has been declared unique
@@ -171,15 +168,44 @@ module ActiveFedora
171
168
  end
172
169
 
173
170
  def property name, properties={}, &block
171
+ if properties.key?(:predicate)
172
+ define_active_triple_accessor(name, properties, &block)
173
+ elsif properties.key?(:datastream)
174
+ define_delegated_accessor(name, properties.merge(multiple: true), &block)
175
+ else
176
+ raise "You must provide `:datastream' or `:predicate' options to property"
177
+ end
178
+ end
179
+
180
+ private
181
+
182
+ def define_active_triple_accessor(name, properties, &block)
174
183
  warn_duplicate_predicates name, properties
175
184
  properties = { multiple: true }.merge(properties)
176
185
  find_or_create_defined_attribute(name, nil, properties)
177
186
  raise ArgumentError, "#{name} is a keyword and not an acceptable property name." if protected_property_name? name
178
187
  reflection = ActiveFedora::Attributes::PropertyBuilder.build(self, name, properties, &block)
179
188
  ActiveTriples::Reflection.add_reflection self, name, reflection
189
+
190
+ add_attribute_indexing_config(name, &block) if block_given?
180
191
  end
181
192
 
182
- private
193
+ def define_delegated_accessor(*fields, &block)
194
+ options = fields.pop
195
+ datastream = options.delete(:datastream).to_s
196
+ raise ArgumentError, "You must provide a datastream to has_attributes" if datastream.blank?
197
+ define_attribute_methods fields
198
+ fields.each do |f|
199
+ create_attribute_reader(f, datastream, options)
200
+ create_attribute_setter(f, datastream, options)
201
+ add_attribute_indexing_config(f, &block) if block_given?
202
+ end
203
+ end
204
+
205
+ def add_attribute_indexing_config(name, &block)
206
+ # TODO the hash can be initalized to return on of these
207
+ index_config[name] ||= ActiveFedora::Indexing::Map::IndexObject.new &block
208
+ end
183
209
 
184
210
  def warn_duplicate_predicates new_name, new_properties
185
211
  new_predicate = new_properties[:predicate]
@@ -54,6 +54,7 @@ module ActiveFedora::Attributes
54
54
  end
55
55
 
56
56
  def build(&block)
57
+ #TODO remove this block stuff
57
58
  NodeConfig.new(name, options[:predicate], options.except(:predicate)) do |config|
58
59
  config.with_index(&block) if block_given?
59
60
  end
@@ -0,0 +1,40 @@
1
+ module ActiveFedora
2
+ class CleanConnection < SimpleDelegator
3
+ def get(*args)
4
+ result = __getobj__.get(*args) do |req|
5
+ prefer_headers = Ldp::PreferHeaders.new(req.headers["Prefer"])
6
+ prefer_headers.omit = prefer_headers.omit | omit_uris
7
+ req.headers["Prefer"] = prefer_headers.to_s
8
+ end
9
+ CleanResult.new(result)
10
+ end
11
+
12
+ private
13
+
14
+ def omit_uris
15
+ [
16
+ RDF::Fcrepo4.ServerManaged,
17
+ RDF::Ldp.PreferContainment,
18
+ RDF::Ldp.PreferEmptyContainer,
19
+ RDF::Ldp.PreferMembership
20
+ ]
21
+ end
22
+
23
+ class CleanResult < SimpleDelegator
24
+ def graph
25
+ @graph ||= clean_graph
26
+ end
27
+
28
+ private
29
+
30
+ def clean_graph
31
+ __getobj__.graph.delete(has_model_query)
32
+ __getobj__.graph
33
+ end
34
+
35
+ def has_model_query
36
+ [nil, ActiveFedora::RDF::Fcrepo::Model.hasModel, nil]
37
+ end
38
+ end
39
+ end
40
+ end
@@ -25,6 +25,10 @@ module ActiveFedora
25
25
  @connection ||= CachingConnection.new(authorized_connection)
26
26
  end
27
27
 
28
+ def clean_connection
29
+ @clean_connection ||= CleanConnection.new(connection)
30
+ end
31
+
28
32
  def ldp_resource_service
29
33
  @service ||= LdpResourceService.new(connection)
30
34
  end
@@ -14,8 +14,8 @@ module ActiveFedora
14
14
  define_model_callbacks :save, :create, :destroy
15
15
  define_model_callbacks :initialize, only: :after
16
16
 
17
- # @param parent_or_url [ActiveFedora::Base, String, Hash, NilClass] the parent resource or the URI of this resource
18
- # @param path_name [String] the path partial relative to the resource
17
+ # @param parent_or_url_or_hash [ActiveFedora::Base, String, Hash, NilClass] the parent resource or the URI of this resource
18
+ # @param path [String] the path partial relative to the resource
19
19
  # @param options [Hash]
20
20
  def initialize(parent_or_url_or_hash = nil, path=nil, options={})
21
21
  case parent_or_url_or_hash
@@ -284,20 +284,20 @@ module ActiveFedora
284
284
 
285
285
  module Streaming
286
286
  # @param range [String] the Range HTTP header
287
- # @returns [Stream] an object that responds to each
287
+ # @return [Stream] an object that responds to each
288
288
  def stream(range = nil)
289
289
  uri = URI.parse(self.uri)
290
290
  FileBody.new(uri, headers(range, authorization_key))
291
291
  end
292
292
 
293
- # @returns current authorization token from Ldp::Client
293
+ # @return [String] current authorization token from Ldp::Client
294
294
  def authorization_key
295
295
  self.ldp_source.client.http.headers.fetch("Authorization", nil)
296
296
  end
297
297
 
298
298
  # @param range [String] from #stream
299
299
  # @param key [String] from #authorization_key
300
- # @returns [Hash]
300
+ # @return [Hash]
301
301
  def headers(range, key, result = Hash.new)
302
302
  result["Range"] = range if range
303
303
  result["Authorization"] = key if key
@@ -1,6 +1,11 @@
1
1
  module ActiveFedora
2
2
  module Indexing
3
3
  extend ActiveSupport::Concern
4
+ extend ActiveSupport::Autoload
5
+
6
+ eager_autoload do
7
+ autoload :Map
8
+ end
4
9
 
5
10
  # Return a Hash representation of this object where keys in the hash are appropriate Solr field names.
6
11
  # @param [Hash] solr_doc (optional) Hash to insert the fields into
@@ -51,6 +56,15 @@ module ActiveFedora
51
56
 
52
57
  module ClassMethods
53
58
 
59
+ # @return ActiveFedora::Indexing::Map
60
+ def index_config
61
+ @index_config ||= if superclass.respond_to?(:index_config)
62
+ superclass.index_config.deep_dup
63
+ else
64
+ ActiveFedora::Indexing::Map.new
65
+ end
66
+ end
67
+
54
68
  def indexer
55
69
  IndexingService
56
70
  end
@@ -0,0 +1,46 @@
1
+ require 'forwardable'
2
+ module ActiveFedora::Indexing
3
+ # This is a description of how properties should map to indexing strategies
4
+ # e.g. 'creator_name' => <IndexObject behaviors=[:stored_searchable, :facetable]>
5
+ class Map
6
+ extend Forwardable
7
+ def_delegators :@hash, :[], :[]=, :each, :keys
8
+
9
+ def initialize(hash = {})
10
+ @hash = hash
11
+ end
12
+
13
+ def dup
14
+ self.class.new(@hash.deep_dup)
15
+ end
16
+
17
+ # this enables a cleaner API for solr integration
18
+ class IndexObject
19
+ attr_accessor :data_type, :behaviors
20
+
21
+ def initialize(&block)
22
+ @behaviors = []
23
+ @data_type = :string
24
+ yield self if block_given?
25
+ end
26
+
27
+ def as(*args)
28
+ @behaviors = args
29
+ end
30
+
31
+ def type(sym)
32
+ @data_type = sym
33
+ end
34
+
35
+ def dup
36
+ self.class.new do |idx|
37
+ idx.behaviors = @behaviors.dup
38
+ end
39
+ end
40
+
41
+ def defaults
42
+ :noop
43
+ end
44
+ end
45
+ end
46
+ end