ddr-models 3.0.0.alpha.2 → 3.0.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -2
  3. data/lib/ddr/actions/fixity_check.rb +8 -5
  4. data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +1 -1
  5. data/lib/ddr/auth/grouper_gateway.rb +51 -53
  6. data/lib/ddr/datastreams/datastream_behavior.rb +65 -66
  7. data/lib/ddr/events/event.rb +2 -2
  8. data/lib/ddr/events/fixity_check_event.rb +3 -2
  9. data/lib/ddr/index/fields.rb +1 -0
  10. data/lib/ddr/managers/derivatives_manager.rb +3 -3
  11. data/lib/ddr/managers/permanent_id_manager.rb +2 -2
  12. data/lib/ddr/models.rb +5 -2
  13. data/lib/ddr/models/attached_file_profile.rb +12 -0
  14. data/lib/ddr/models/attached_files_profile.rb +21 -0
  15. data/lib/ddr/models/base.rb +77 -74
  16. data/lib/ddr/models/describable.rb +3 -3
  17. data/lib/ddr/models/governable.rb +1 -1
  18. data/lib/ddr/models/indexing.rb +1 -0
  19. data/lib/ddr/models/licenses/license.rb +8 -2
  20. data/lib/ddr/models/metadata/descriptive_metadata.rb +6 -10
  21. data/lib/ddr/models/metadata/metadata_mapping.rb +45 -0
  22. data/lib/ddr/models/object_api.rb +11 -0
  23. data/lib/ddr/models/solr_document.rb +16 -9
  24. data/lib/ddr/models/url_safe_id.rb +9 -0
  25. data/lib/ddr/models/version.rb +1 -1
  26. data/lib/ddr/utils.rb +3 -3
  27. data/spec/auth/ability_spec.rb +9 -9
  28. data/spec/jobs/fits_file_characterization_spec.rb +3 -3
  29. data/spec/models/active_fedora_base_spec.rb +4 -4
  30. data/spec/models/active_fedora_datastream_spec.rb +6 -8
  31. data/spec/models/collection_spec.rb +1 -1
  32. data/spec/models/descriptive_metadata_spec.rb +0 -3
  33. data/spec/models/effective_license_spec.rb +4 -4
  34. data/spec/models/indexing_spec.rb +1 -1
  35. data/spec/models/license_spec.rb +3 -3
  36. data/spec/spec_helper.rb +6 -5
  37. data/spec/support/shared_examples_for_ddr_models.rb +1 -0
  38. data/spec/support/shared_examples_for_describables.rb +2 -2
  39. data/spec/support/shared_examples_for_events.rb +6 -6
  40. data/spec/support/shared_examples_for_fixity_checkable_spec.rb +15 -0
  41. data/spec/support/shared_examples_for_governables.rb +1 -1
  42. metadata +9 -4
  43. data/lib/ddr/models/metadata/metadata_mapper.rb +0 -32
  44. data/lib/ddr/models/metadata/metadata_mappers.rb +0 -18
@@ -0,0 +1,12 @@
1
+ require "delegate"
2
+
3
+ module Ddr::Models
4
+ class AttachedFileProfile < SimpleDelegator
5
+ include ActiveModel::Serializers::JSON
6
+
7
+ def attributes
8
+ { "size" => nil }
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ module Ddr::Models
2
+ class AttachedFilesProfile
3
+ include ActiveModel::Serializers::JSON
4
+
5
+ attr_reader :files_hash
6
+
7
+ # @param files_hash [ActiveFedora::FilesHash]
8
+ def initialize(files_hash)
9
+ @files_hash = files_hash
10
+ end
11
+
12
+ def attributes
13
+ files_hash.keys.each_with_object({}) { |k, memo| memo[k.to_s] = nil }
14
+ end
15
+
16
+ def read_attribute_for_serialization(key)
17
+ AttachedFileProfile.new(files_hash[key])
18
+ end
19
+
20
+ end
21
+ end
@@ -1,95 +1,98 @@
1
- module Ddr
2
- module Models
3
- class Base < ActiveFedora::Base
1
+ module Ddr::Models
2
+ class Base < ActiveFedora::Base
4
3
 
5
- include Describable
6
- include Governable
7
- include HasThumbnail
8
- include EventLoggable
9
- include FixityCheckable
10
- include FileManagement
11
- include Indexing
12
- include Hydra::Validations
13
- include HasAdminMetadata
4
+ include ObjectApi
5
+ include Describable
6
+ include Governable
7
+ include HasThumbnail
8
+ include EventLoggable
9
+ include FixityCheckable
10
+ include FileManagement
11
+ include Indexing
12
+ include Hydra::Validations
13
+ include HasAdminMetadata
14
14
 
15
- after_destroy do
16
- notify_event :deletion
17
- end
15
+ after_destroy do
16
+ notify_event :deletion
17
+ end
18
18
 
19
- def copy_admin_policy_or_roles_from(other)
20
- copy_resource_roles_from(other) unless copy_admin_policy_from(other)
21
- end
19
+ def attached_files_profile
20
+ AttachedFilesProfile.new(attached_files)
21
+ end
22
22
 
23
- def association_query(association)
24
- raise NotImplementedError, "The previous implementation does not work with ActiveFedora 9."
25
- end
23
+ def copy_admin_policy_or_roles_from(other)
24
+ copy_resource_roles_from(other) unless copy_admin_policy_from(other)
25
+ end
26
26
 
27
- # e.g., "Collection duke:1"
28
- def model_pid
29
- [self.class.to_s, pid].join(" ")
30
- end
27
+ def association_query(association)
28
+ raise NotImplementedError, "The previous implementation does not work with ActiveFedora 9."
29
+ end
31
30
 
32
- # @override ActiveFedora::Core
33
- # See ActiveFedora overrides in engine initializers
34
- def adapt_to_cmodel
35
- super
36
- rescue ::TypeError
37
- raise ContentModelError, "Cannot adapt to nil content model."
38
- end
31
+ # e.g., "Collection duke:1"
32
+ def model_pid
33
+ [self.class.to_s, pid].join(" ")
34
+ end
39
35
 
40
- def has_extracted_text?
41
- false
42
- end
36
+ # @override ActiveFedora::Core
37
+ # See ActiveFedora overrides in engine initializers
38
+ def adapt_to_cmodel
39
+ super
40
+ rescue ::TypeError
41
+ raise ContentModelError, "Cannot adapt to nil content model."
42
+ end
43
43
 
44
- def adminMetadata
45
- self
46
- end
44
+ def has_extracted_text?
45
+ false
46
+ end
47
47
 
48
- # Moves the first (descriptive metadata) identifier into
49
- # (administrative metadata) local_id according to the following
50
- # rubric:
51
- #
52
- # No existing local_id:
53
- # - Set local_id to first identifier value
54
- # - Remove first identifier value
55
- #
56
- # Existing local_id:
57
- # Same as first identifier value
58
- # - Remove first identifier value
59
- # Not same as first identifier value
60
- # :replace option is true
61
- # - Set local_id to first identifier value
62
- # - Remove first identifier value
63
- # :replace option is false
64
- # - Do nothing
65
- #
66
- # Returns true or false depending on whether the object was
67
- # changed by this method
68
- def move_first_identifier_to_local_id(replace: true)
69
- moved = false
70
- identifiers = descMetadata.identifier.to_a
71
- first_id = identifiers.shift
72
- if first_id
73
- if local_id.blank?
74
- self.local_id = first_id
48
+ def adminMetadata
49
+ self
50
+ end
51
+
52
+ # Moves the first (descriptive metadata) identifier into
53
+ # (administrative metadata) local_id according to the following
54
+ # rubric:
55
+ #
56
+ # No existing local_id:
57
+ # - Set local_id to first identifier value
58
+ # - Remove first identifier value
59
+ #
60
+ # Existing local_id:
61
+ # Same as first identifier value
62
+ # - Remove first identifier value
63
+ # Not same as first identifier value
64
+ # :replace option is true
65
+ # - Set local_id to first identifier value
66
+ # - Remove first identifier value
67
+ # :replace option is false
68
+ # - Do nothing
69
+ #
70
+ # Returns true or false depending on whether the object was
71
+ # changed by this method
72
+ def move_first_identifier_to_local_id(replace: true)
73
+ moved = false
74
+ identifiers = descMetadata.identifier.to_a
75
+ first_id = identifiers.shift
76
+ if first_id
77
+ if local_id.blank?
78
+ self.local_id = first_id
79
+ self.descMetadata.identifier = identifiers
80
+ moved = true
81
+ else
82
+ if local_id == first_id
75
83
  self.descMetadata.identifier = identifiers
76
84
  moved = true
77
85
  else
78
- if local_id == first_id
86
+ if replace
87
+ self.local_id = first_id
79
88
  self.descMetadata.identifier = identifiers
80
89
  moved = true
81
- else
82
- if replace
83
- self.local_id = first_id
84
- self.descMetadata.identifier = identifiers
85
- moved = true
86
- end
87
90
  end
88
91
  end
89
92
  end
90
- moved
91
93
  end
92
-
94
+ moved
93
95
  end
96
+
94
97
  end
95
98
  end
@@ -31,8 +31,8 @@ module Ddr::Models
31
31
  when :required
32
32
  desc_metadata_terms(:defined_attributes).select {|t| required? t}
33
33
  when :dcterms
34
- MetadataMapper.dc11.unqualified_names +
35
- (MetadataMapper.dcterms.unqualified_names - MetadataMapper.dc11.unqualified_names)
34
+ MetadataMapping.dc11.unqualified_names +
35
+ (MetadataMapping.dcterms.unqualified_names - MetadataMapping.dc11.unqualified_names)
36
36
  when :dcterms_elements11
37
37
  Ddr::Vocab::Vocabulary.term_names(RDF::DC11)
38
38
  when :duke
@@ -48,7 +48,7 @@ module Ddr::Models
48
48
  end
49
49
 
50
50
  def desc_metadata_attributes
51
- MetadataMapper.dc11.unqualified_names
51
+ MetadataMapping.dc11.unqualified_names
52
52
  end
53
53
 
54
54
  def desc_metadata_values(term)
@@ -36,7 +36,7 @@ module Ddr
36
36
  when other.has_admin_policy?
37
37
  other.admin_policy_id
38
38
  when other.is_a?(Collection)
39
- other.pid
39
+ other.id
40
40
  end
41
41
  # self.admin_policy_id = other.admin_policy_id if other.has_admin_policy?
42
42
  end
@@ -13,6 +13,7 @@ module Ddr
13
13
  fields = {
14
14
  ACCESS_ROLE => roles.to_json,
15
15
  ADMIN_SET => admin_set,
16
+ ATTACHED_FILES => attached_files_profile.to_json,
16
17
  BOX_NUMBER_FACET => desc_metadata_values('box_number'),
17
18
  CREATOR_FACET => descMetadata.creator,
18
19
  DATE_FACET => descMetadata.date,
@@ -2,17 +2,23 @@ require "ddr_aux/client"
2
2
 
3
3
  module Ddr::Models
4
4
  class License < DdrAux::Client::License
5
+ extend Deprecation
5
6
 
6
- attr_accessor :pid
7
+ attr_accessor :object_id
7
8
 
8
9
  def self.call(obj)
9
10
  if obj.license
10
11
  license = find(url: obj.license)
11
- license.pid = obj.pid
12
+ license.object_id = obj.id
12
13
  license
13
14
  end
14
15
  end
15
16
 
17
+ def pid
18
+ Deprecation.warn(License, "Use `object_id` instead.")
19
+ object_id
20
+ end
21
+
16
22
  def to_s
17
23
  title
18
24
  end
@@ -5,21 +5,15 @@ module Ddr::Models
5
5
  extend Forwardable
6
6
  include Metadata
7
7
 
8
- class << self
9
- def mappers
10
- [ MetadataMapper.dcterms, MetadataMapper.duketerms ]
11
- end
12
-
13
- def mapper
14
- @mapper ||= mappers.reduce(&:merge)
15
- end
8
+ class_attribute :mappings
16
9
 
10
+ class << self
17
11
  def mapping
18
- mapper.mapping
12
+ @mapping ||= mappings.reduce(&:merge)
19
13
  end
20
14
 
21
15
  def unqualified_names
22
- mapper.unqualified_names
16
+ mapping.unqualified_names
23
17
  end
24
18
 
25
19
  def field_names
@@ -32,6 +26,8 @@ module Ddr::Models
32
26
  end
33
27
  end
34
28
 
29
+ self.mappings = [ MetadataMapping.dcterms, MetadataMapping.duketerms ].freeze
30
+
35
31
  attr_reader :object
36
32
 
37
33
  def_delegators :object, *field_readers
@@ -0,0 +1,45 @@
1
+ module Ddr::Models
2
+ class MetadataMapping < SimpleDelegator
3
+
4
+ class << self
5
+ def build(vocab, label=nil)
6
+ mapping = vocab.terms.each_with_object({}) do |term, memo|
7
+ memo[term.qualified_name] = term
8
+ end
9
+ new(mapping, label)
10
+ end
11
+
12
+ def dc11
13
+ @dc11 ||= build(MetadataVocabulary.dc11, "DC Elements").freeze
14
+ end
15
+
16
+ def dcterms
17
+ @dcterms ||= build(MetadataVocabulary.dcterms, "DC Terms").freeze
18
+ end
19
+
20
+ def duketerms
21
+ @duketerms ||= build(MetadataVocabulary.duketerms, "Duke Terms").freeze
22
+ end
23
+ end
24
+
25
+ attr_accessor :label
26
+
27
+ def initialize(mapping=Hash.new, label=nil)
28
+ super(mapping)
29
+ @label = label
30
+ end
31
+
32
+ def terms
33
+ values
34
+ end
35
+
36
+ def unqualified_names
37
+ terms.map(&:unqualified_name)
38
+ end
39
+
40
+ def merge(other)
41
+ MetadataMapping.new(__getobj__.merge(other))
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,11 @@
1
+ module Ddr::Models
2
+ #
3
+ # ObjectApi
4
+ #
5
+ # Common methods abstracted from classes that represent repository objects,
6
+ # principally SolrDocument and subclasses of Ddr::Models::Base.
7
+ #
8
+ module ObjectApi
9
+
10
+ end
11
+ end
@@ -3,24 +3,26 @@ require 'json'
3
3
  module Ddr::Models
4
4
  module SolrDocument
5
5
  extend ActiveSupport::Concern
6
-
7
- included do
8
- alias_method :pid, :id
9
- end
6
+ extend Deprecation
7
+ include ObjectApi
10
8
 
11
9
  class NotFound < Error; end
12
10
 
13
11
  module ClassMethods
14
- def find(pid_or_uri)
15
- pid = pid_or_uri.sub(/\Ainfo:fedora\//, "")
16
- query = Ddr::Index::QueryBuilder.build { |q| q.id(pid) }
12
+ def find(id)
13
+ query = Ddr::Index::QueryBuilder.build { |q| q.id(id) }
17
14
  if doc = query.docs.first
18
15
  return doc
19
16
  end
20
- raise NotFound, "SolrDocument not found for \"#{pid_or_uri}\"."
17
+ raise NotFound, "SolrDocument not found for \"#{id}\"."
21
18
  end
22
19
  end
23
20
 
21
+ def pid
22
+ Deprecation.warn(SolrDocument, "Use `id` instead.")
23
+ id
24
+ end
25
+
24
26
  def inspect
25
27
  "#<#{self.class.name} id=#{id.inspect}>"
26
28
  end
@@ -75,7 +77,12 @@ module Ddr::Models
75
77
  end
76
78
 
77
79
  def datastreams
78
- object_profile["datastreams"]
80
+ Deprecation.warn(SolrDocument, "Use `attached_files` instead.")
81
+ attached_files
82
+ end
83
+
84
+ def attached_files
85
+ (get_json(Ddr::Index::Fields::ATTACHED_FILES) || {}).with_indifferent_access
79
86
  end
80
87
 
81
88
  def has_datastream?(dsID)
@@ -0,0 +1,9 @@
1
+ module Ddr::Models
2
+ class UrlSafeId
3
+
4
+ def self.call(obj)
5
+ obj.id.gsub(/\//, "%2F")
6
+ end
7
+
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module Ddr
2
2
  module Models
3
- VERSION = "3.0.0.alpha.2"
3
+ VERSION = "3.0.0.alpha.3"
4
4
  end
5
5
  end
@@ -95,13 +95,13 @@ module Ddr::Utils
95
95
  objs = []
96
96
  ActiveFedora::Base.find_each( { Ddr::Index::Fields::IDENTIFIER_ALL => identifier }, { :cast => true } ) { |o| objs << o }
97
97
  pids = []
98
- objs.each { |obj| pids << obj.pid }
98
+ objs.each { |obj| pids << obj.id }
99
99
  if model.present?
100
- objs.each { |obj| pids.delete(obj.pid) unless obj.is_a?(model.constantize) }
100
+ objs.each { |obj| pids.delete(obj.id) unless obj.is_a?(model.constantize) }
101
101
  end
102
102
  if collection.present?
103
103
  objs.each do |obj|
104
- pids.delete(obj.pid) unless obj == collection || obj.parent == collection
104
+ pids.delete(obj.id) unless obj == collection || obj.parent == collection
105
105
  end
106
106
  end
107
107
  case pids.size