active-fedora 9.4.3 → 9.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de5b5046afb1dd762565465806e9b98a67c21727
4
- data.tar.gz: 46a49e17d79a44566e95a61403b233b61a37e556
3
+ metadata.gz: d20da0e6b44ea16a3ea8b082bf4d7ace579231c0
4
+ data.tar.gz: a0d115e8e0897dfac1ef208ee9b936b51c0f679b
5
5
  SHA512:
6
- metadata.gz: fa2eec62f59fde87474c31cf72c28ba1f8bfbc3dc8377869d1d9f5bf2d26de643e834d4e34e5b9db1dfa432d3d5bc620791a92bedfcfff24ce2ed23646a99051
7
- data.tar.gz: ad05b8ba63965874e5d56e8d2096954705088fc2b19f6fab47aaaaa7cf3fa300d523e2e27141dd78061246a66df7f94d9bdf938b0494013bc51c3aa1c5d5fb03
6
+ metadata.gz: 62cf90d783c51e26e1ff7ac3cb19a9ab5c3c5daff025900244c076d61b9f7a6533a9daab5951bd9225a445ccd3287a59ac0311673919338a0d6ffd17b6a5b7c2
7
+ data.tar.gz: a556f5e96eb8b20134a6b9e58c397717882a36184d6972ea3fb705e25a899845b36dfc0ddfd8d524d77828c979f1c8157895e628f2af1aa6015db975c1cffd0c
@@ -1,3 +1,16 @@
1
+ v9.5.0
2
+ 2015-10-16: query for nil creates correct query [Justin Coyne]
3
+
4
+ 2015-10-16: Support both Fedora and Premis fixity predicates [Adam Wead]
5
+
6
+ 2015-10-12: AssociationHash - alias to [David Chandek-Stark]
7
+
8
+ 2015-10-12: Fixed syntax error in raise statement [David Chandek-Stark]
9
+
10
+ 2015-10-02: Let autoload do its thing [Justin Coyne]
11
+
12
+ 2015-09-28: Add support for contained RDF sources. [Trey Terrell]
13
+
1
14
  v9.4.3
2
15
  2015-09-30: Don't mark an attribute as changed if it's set to the same value
3
16
  [Justin Coyne]
@@ -38,6 +38,7 @@ module ActiveFedora #:nodoc:
38
38
  extend ActiveSupport::Autoload
39
39
 
40
40
  eager_autoload do
41
+ autoload :AssociationHash
41
42
  autoload :AssociationRelation
42
43
  autoload :Associations
43
44
  autoload :AttachedFiles
@@ -0,0 +1,117 @@
1
+ module ActiveFedora
2
+ ##
3
+ # Used as an access method for associations on a model, given some
4
+ # reflections.
5
+ class AssociationHash
6
+ def initialize (model, reflections)
7
+ @base = model
8
+ @reflections = reflections
9
+ end
10
+
11
+ def [] (name)
12
+ association(name).reader if association(name)
13
+ end
14
+
15
+ def []= (name, object)
16
+ association(name).writer(object) if association(name)
17
+ end
18
+
19
+ def association(name)
20
+ # Check to see if the key exists before casting to a symbol, because symbols
21
+ # are not garbage collected in earlier versions of Ruby
22
+ @base.association(name.to_sym) if key?(name)
23
+ end
24
+
25
+ def reflections
26
+ @reflections
27
+ end
28
+
29
+ def merge(other_hash)
30
+ Merged.new(self, other_hash)
31
+ end
32
+
33
+ def each
34
+ keys.each do |k|
35
+ yield k, self[k]
36
+ end
37
+ end
38
+
39
+ def keys
40
+ reflections.keys
41
+ end
42
+
43
+ # Check that the key exists with indifferent access (symbol or string) in a
44
+ # manner that avoids generating extra symbols. Symbols are not garbage collected
45
+ # in earlier versions of ruby.
46
+ def key?(key)
47
+ keys.include?(key) || keys.map(&:to_s).include?(key)
48
+ end
49
+ alias_method :include?, :key?
50
+
51
+ def values
52
+ keys.map { |k| self[k] }
53
+ end
54
+
55
+ def has_key?(key)
56
+ keys.include?(key)
57
+ end
58
+
59
+ def size
60
+ keys.size
61
+ end
62
+
63
+ def empty?
64
+ reflections.empty?
65
+ end
66
+
67
+ def each_value
68
+ keys.each do |k|
69
+ yield self[k]
70
+ end
71
+ end
72
+
73
+ def changed
74
+ select do |_, obj|
75
+ obj.changed?
76
+ end
77
+ end
78
+
79
+ def select
80
+ keys.each_with_object({}) do |k, h|
81
+ val = self[k]
82
+ h[k] = val if yield k, val
83
+ end
84
+ end
85
+
86
+ def freeze
87
+ keys.each do |name|
88
+ association(name).reader.freeze if association(name).loaded?
89
+ end
90
+ super
91
+ end
92
+ end
93
+ ##
94
+ # Represents the result of merging two association hashes.
95
+ # @note As the keys can come from multiple models, the attributes become
96
+ # unwritable.
97
+ class Merged < AssociationHash
98
+ attr_reader :first, :second
99
+
100
+ def initialize(first, second)
101
+ @first = first
102
+ @second = second
103
+ end
104
+
105
+ def [] (name)
106
+ first[name] || second[name]
107
+ end
108
+
109
+ def []= (name)
110
+ raise NotImplementedError, "Unable to set properties on a merged association hash."
111
+ end
112
+
113
+ def keys
114
+ first.keys + second.keys
115
+ end
116
+ end
117
+ end
@@ -10,31 +10,30 @@ module ActiveFedora
10
10
  end
11
11
 
12
12
  module Associations
13
-
14
13
  extend ActiveSupport::Concern
14
+ extend ActiveSupport::Autoload
15
15
 
16
- autoload :Association, 'active_fedora/associations/association'
17
- autoload :AssociationScope, 'active_fedora/associations/association_scope'
18
- autoload :SingularAssociation, 'active_fedora/associations/singular_association'
19
- autoload :RDF, 'active_fedora/associations/rdf'
20
- autoload :SingularRDF, 'active_fedora/associations/singular_rdf'
21
- autoload :CollectionAssociation, 'active_fedora/associations/collection_association'
22
- autoload :CollectionProxy, 'active_fedora/associations/collection_proxy'
23
- autoload :ContainerProxy, 'active_fedora/associations/container_proxy'
16
+ autoload :Association
17
+ autoload :SingularAssociation
18
+ autoload :RDF
19
+ autoload :SingularRDF
20
+ autoload :CollectionAssociation
21
+ autoload :CollectionProxy
22
+ autoload :ContainerProxy
24
23
 
25
- autoload :HasManyAssociation, 'active_fedora/associations/has_many_association'
26
- autoload :BelongsToAssociation, 'active_fedora/associations/belongs_to_association'
27
- autoload :HasAndBelongsToManyAssociation, 'active_fedora/associations/has_and_belongs_to_many_association'
28
- autoload :BasicContainsAssociation, 'active_fedora/associations/basic_contains_association'
29
- autoload :DirectlyContainsAssociation, 'active_fedora/associations/directly_contains_association'
30
- autoload :DirectlyContainsOneAssociation, 'active_fedora/associations/directly_contains_one_association'
31
- autoload :IndirectlyContainsAssociation, 'active_fedora/associations/indirectly_contains_association'
32
- autoload :ContainsAssociation, 'active_fedora/associations/contains_association'
33
- autoload :DeleteProxy, 'active_fedora/associations/delete_proxy'
34
- autoload :ContainedFinder, 'active_fedora/associations/contained_finder'
35
- autoload :RecordComposite, 'active_fedora/associations/record_composite'
36
- autoload :IDComposite, 'active_fedora/associations/id_composite'
37
- autoload :NullValidator, 'active_fedora/associations/null_validator'
24
+ autoload :HasManyAssociation
25
+ autoload :BelongsToAssociation
26
+ autoload :HasAndBelongsToManyAssociation
27
+ autoload :BasicContainsAssociation
28
+ autoload :DirectlyContainsAssociation
29
+ autoload :DirectlyContainsOneAssociation
30
+ autoload :IndirectlyContainsAssociation
31
+ autoload :ContainsAssociation
32
+ autoload :DeleteProxy
33
+ autoload :ContainedFinder
34
+ autoload :RecordComposite
35
+ autoload :IDComposite
36
+ autoload :NullValidator
38
37
 
39
38
  module Builder
40
39
  autoload :Association, 'active_fedora/associations/builder/association'
@@ -53,6 +52,10 @@ module ActiveFedora
53
52
  autoload :SingularProperty, 'active_fedora/associations/builder/singular_property'
54
53
  end
55
54
 
55
+ eager_autoload do
56
+ autoload :AssociationScope
57
+ end
58
+
56
59
  # Clears out the association cache.
57
60
  def clear_association_cache #:nodoc:
58
61
  @association_cache.clear if persisted?
@@ -162,13 +165,13 @@ module ActiveFedora
162
165
  # This method is used to specify the details of a contained resource.
163
166
  # Pass the name as the first argument and a hash of options as the second argument
164
167
  # Note that this method doesn't actually execute the block, but stores it, to be executed
165
- # by any the implementation of the datastream(specified as :class_name)
168
+ # by any the implementation of the resource(specified as :class_name)
166
169
  #
167
170
  # @param [String] name the handle to refer to this child as
168
171
  # @param [Hash] options
169
- # @option options [Class] :class_name The class that will represent this child, should extend ``ActiveFedora::File''
172
+ # @option options [Class] :class_name The class that will represent this child, should extend ``ActiveFedora::File'' or ``ActiveFedora::Base''
170
173
  # @option options [String] :url
171
- # @option options [Boolean] :autocreate Always create this datastream on new objects
174
+ # @option options [Boolean] :autocreate Always create this resource on new objects
172
175
  # @yield block executed by some types of child resources
173
176
  def contains(name, options = {}, &block)
174
177
  options[:block] = block if block
@@ -7,13 +7,13 @@ module ActiveFedora
7
7
  end
8
8
 
9
9
  def find_target
10
- reflection.build_association(target_uri) do |record|
10
+ find_or_initialize_target do |record|
11
11
  configure_datastream(record) if reflection.options[:block]
12
12
  end
13
13
  end
14
14
 
15
15
  def target_uri
16
- "#{owner.uri}/#{reflection.name}"
16
+ "#{owner.id}/#{reflection.name}"
17
17
  end
18
18
 
19
19
  private
@@ -23,6 +23,18 @@ module ActiveFedora
23
23
  super
24
24
  end
25
25
 
26
+ def find_or_initialize_target(&block)
27
+ begin
28
+ if reflection.klass < ActiveFedora::File
29
+ reflection.build_association(target_uri, &block)
30
+ else
31
+ reflection.klass.find(target_uri)
32
+ end
33
+ rescue ActiveFedora::ObjectNotFoundError
34
+ reflection.build_association(target_uri, &block)
35
+ end
36
+ end
37
+
26
38
  def replace(record)
27
39
  if record
28
40
  raise_on_type_mismatch(record)
@@ -21,7 +21,12 @@ module ActiveFedora::Associations::Builder
21
21
  set_uri = uri.kind_of?(RDF::URI) ? uri.value.present? : uri.present?
22
22
  if set_uri
23
23
  file_uri = "#{uri}/#{name}"
24
- file.uri = file_uri
24
+ begin
25
+ file.uri = file_uri
26
+ rescue ActiveFedora::AlreadyPersistedError
27
+ end
28
+ end
29
+ if file.respond_to?(:exists!)
25
30
  file.exists! if contains_assertions.include?(file_uri)
26
31
  end
27
32
  end
@@ -5,6 +5,9 @@ module ActiveFedora::Associations
5
5
  class IDComposite
6
6
  attr_reader :ids, :id_translator
7
7
  include Enumerable
8
+ # @param [Array<#to_s>] ids An array of ids or URIs to convert to IDs.
9
+ # @param [#call] id_translator An object to handle the conversion of a URI
10
+ # to an ID.
8
11
  def initialize(ids, id_translator)
9
12
  @ids = ids
10
13
  @id_translator = id_translator
@@ -20,7 +23,7 @@ module ActiveFedora::Associations
20
23
  private
21
24
 
22
25
  def convert(id)
23
- if id.start_with?("http")
26
+ if id.to_s.start_with?("http")
24
27
  id_translator.call(id)
25
28
  else
26
29
  id
@@ -37,6 +37,18 @@ module ActiveFedora
37
37
  run_callbacks :initialize
38
38
  end
39
39
 
40
+ ##
41
+ # @param [#to_s] uri a full fedora URI or relative ID to set this resource
42
+ # to.
43
+ # @note This can only be run on an unpersisted resource.
44
+ def uri=(uri)
45
+ if persisted?
46
+ raise AlreadyPersistedError, "You can not set a URI for a persisted ActiveFedora object."
47
+ else
48
+ @ldp_source = build_ldp_resource(self.class.uri_to_id(uri))
49
+ end
50
+ end
51
+
40
52
  # Reloads the object from Fedora.
41
53
  def reload
42
54
  check_persistence unless persisted?
@@ -76,4 +76,8 @@ module ActiveFedora #:nodoc:
76
76
  # Raised when Fedora returns a version without a create date
77
77
  class VersionLacksCreateDate < ActiveFedoraError
78
78
  end
79
+
80
+ # Raised when you try to set a URI to an already persisted Base object.
81
+ class AlreadyPersistedError < ActiveFedoraError
82
+ end
79
83
  end
@@ -35,8 +35,11 @@ module ActiveFedora
35
35
  case parent_or_url_or_hash
36
36
  when Hash
37
37
  @ldp_source = build_ldp_resource_via_uri
38
- when nil, String, ::RDF::URI
39
- @ldp_source = build_ldp_resource_via_uri parent_or_url_or_hash
38
+ when nil
39
+ @ldp_source = build_ldp_resource_via_uri nil
40
+ when String, ::RDF::URI
41
+ id = ActiveFedora::Associations::IDComposite.new([parent_or_url_or_hash], translate_uri_to_id).first
42
+ @ldp_source = build_ldp_resource id
40
43
  when ActiveFedora::Base
41
44
  Deprecation.warn File, "Initializing a file by passing a container is deprecated. Initialize with a uri instead. This capability will be removed in active-fedora 10.0"
42
45
  uri = if parent_or_url_or_hash.uri.kind_of?(::RDF::URI) && parent_or_url_or_hash.uri.value.empty?
@@ -1,82 +1,15 @@
1
- require 'forwardable'
2
-
3
1
  module ActiveFedora
4
- class FilesHash
5
- extend Forwardable
6
-
2
+ class FilesHash < AssociationHash
7
3
  def initialize (model)
8
4
  @base = model
9
5
  end
10
6
 
11
- def [] (name)
12
- association(name).reader if association(name)
13
- end
14
-
15
- def []= (name, object)
16
- association(name).writer(object) if association(name)
17
- end
18
-
19
- def association(name)
20
- # Check to see if the key exists before casting to a symbol, because symbols
21
- # are not garbage collected in earlier versions of Ruby
22
- @base.association(name.to_sym) if key?(name)
23
- end
24
-
25
7
  def reflections
26
8
  @base.class.child_resource_reflections
27
9
  end
28
10
 
29
- def each
30
- keys.each do |k|
31
- yield k, self[k]
32
- end
33
- end
34
-
35
11
  def keys
36
12
  reflections.keys + @base.undeclared_files
37
13
  end
38
-
39
- # Check that the key exists with indifferent access (symbol or string) in a
40
- # manner that avoids generating extra symbols. Symbols are not garbage collected
41
- # in earlier versions of ruby.
42
- def key?(key)
43
- keys.include?(key) || keys.map(&:to_s).include?(key)
44
- end
45
-
46
- def values
47
- keys.map { |k| self[k] }
48
- end
49
-
50
- def has_key?(key)
51
- keys.include?(key)
52
- end
53
-
54
- def size
55
- keys.size
56
- end
57
-
58
- def empty?
59
- reflections.empty?
60
- end
61
-
62
- def each_value
63
- keys.each do |k|
64
- yield self[k]
65
- end
66
- end
67
-
68
- def select
69
- keys.each_with_object({}) do |k, h|
70
- val = self[k]
71
- h[k] = val if yield k, val
72
- end
73
- end
74
-
75
- def freeze
76
- keys.each do |name|
77
- association(name).reader.freeze if association(name).loaded?
78
- end
79
- super
80
- end
81
14
  end
82
15
  end
@@ -11,26 +11,35 @@ module ActiveFedora
11
11
  end
12
12
 
13
13
  # Executes a fixity check on Fedora and saves the Faraday::Response.
14
- # Returns true when the fixity check was successfully.
14
+ # @return true or false
15
15
  def check
16
16
  @response = get_fixity_response_from_fedora
17
- status.match("SUCCESS") ? true : false
17
+ status.include?(success)
18
18
  end
19
19
 
20
20
  def status
21
- fixity_graph.query(predicate: status_predicate).map(&:object).first.to_s
21
+ fixity_graph.query(predicate: premis_status_predicate).map(&:object) +
22
+ fixity_graph.query(predicate: fedora_status_predicate).map(&:object)
22
23
  end
23
24
 
24
25
  private
25
26
 
27
+ def premis_status_predicate
28
+ ::RDF::Vocab::PREMIS.hasEventOutcome
29
+ end
30
+
26
31
  # Fcrepo4.status was used by Fedora < 4.3, but it was removed
27
32
  # from the 2015-07-24 version of the fedora 4 ontology
28
33
  # http://fedora.info/definitions/v4/2015/07/24/repository and
29
34
  # from rdf-vocab in version 0.8.5
30
- def status_predicate
35
+ def fedora_status_predicate
31
36
  ::RDF::URI("http://fedora.info/definitions/v4/repository#status")
32
37
  end
33
38
 
39
+ def success
40
+ ::RDF::Literal.new("SUCCESS")
41
+ end
42
+
34
43
  def get_fixity_response_from_fedora
35
44
  uri = target + "/fcr:fixity"
36
45
  ActiveFedora.fedora.connection.get(encoded_url(uri))