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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -2
- data/lib/ddr/actions/fixity_check.rb +8 -5
- data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +1 -1
- data/lib/ddr/auth/grouper_gateway.rb +51 -53
- data/lib/ddr/datastreams/datastream_behavior.rb +65 -66
- data/lib/ddr/events/event.rb +2 -2
- data/lib/ddr/events/fixity_check_event.rb +3 -2
- data/lib/ddr/index/fields.rb +1 -0
- data/lib/ddr/managers/derivatives_manager.rb +3 -3
- data/lib/ddr/managers/permanent_id_manager.rb +2 -2
- data/lib/ddr/models.rb +5 -2
- data/lib/ddr/models/attached_file_profile.rb +12 -0
- data/lib/ddr/models/attached_files_profile.rb +21 -0
- data/lib/ddr/models/base.rb +77 -74
- data/lib/ddr/models/describable.rb +3 -3
- data/lib/ddr/models/governable.rb +1 -1
- data/lib/ddr/models/indexing.rb +1 -0
- data/lib/ddr/models/licenses/license.rb +8 -2
- data/lib/ddr/models/metadata/descriptive_metadata.rb +6 -10
- data/lib/ddr/models/metadata/metadata_mapping.rb +45 -0
- data/lib/ddr/models/object_api.rb +11 -0
- data/lib/ddr/models/solr_document.rb +16 -9
- data/lib/ddr/models/url_safe_id.rb +9 -0
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/utils.rb +3 -3
- data/spec/auth/ability_spec.rb +9 -9
- data/spec/jobs/fits_file_characterization_spec.rb +3 -3
- data/spec/models/active_fedora_base_spec.rb +4 -4
- data/spec/models/active_fedora_datastream_spec.rb +6 -8
- data/spec/models/collection_spec.rb +1 -1
- data/spec/models/descriptive_metadata_spec.rb +0 -3
- data/spec/models/effective_license_spec.rb +4 -4
- data/spec/models/indexing_spec.rb +1 -1
- data/spec/models/license_spec.rb +3 -3
- data/spec/spec_helper.rb +6 -5
- data/spec/support/shared_examples_for_ddr_models.rb +1 -0
- data/spec/support/shared_examples_for_describables.rb +2 -2
- data/spec/support/shared_examples_for_events.rb +6 -6
- data/spec/support/shared_examples_for_fixity_checkable_spec.rb +15 -0
- data/spec/support/shared_examples_for_governables.rb +1 -1
- metadata +9 -4
- data/lib/ddr/models/metadata/metadata_mapper.rb +0 -32
- data/lib/ddr/models/metadata/metadata_mappers.rb +0 -18
@@ -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
|
data/lib/ddr/models/base.rb
CHANGED
@@ -1,95 +1,98 @@
|
|
1
|
-
module Ddr
|
2
|
-
|
3
|
-
class Base < ActiveFedora::Base
|
1
|
+
module Ddr::Models
|
2
|
+
class Base < ActiveFedora::Base
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
15
|
+
after_destroy do
|
16
|
+
notify_event :deletion
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def attached_files_profile
|
20
|
+
AttachedFilesProfile.new(attached_files)
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
27
|
+
def association_query(association)
|
28
|
+
raise NotImplementedError, "The previous implementation does not work with ActiveFedora 9."
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
44
|
+
def has_extracted_text?
|
45
|
+
false
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
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
|
-
|
35
|
-
(
|
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
|
-
|
51
|
+
MetadataMapping.dc11.unqualified_names
|
52
52
|
end
|
53
53
|
|
54
54
|
def desc_metadata_values(term)
|
data/lib/ddr/models/indexing.rb
CHANGED
@@ -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 :
|
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.
|
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
|
-
|
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
|
-
|
12
|
+
@mapping ||= mappings.reduce(&:merge)
|
19
13
|
end
|
20
14
|
|
21
15
|
def unqualified_names
|
22
|
-
|
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
|
@@ -3,24 +3,26 @@ require 'json'
|
|
3
3
|
module Ddr::Models
|
4
4
|
module SolrDocument
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
|
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(
|
15
|
-
|
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 \"#{
|
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
|
-
|
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)
|
data/lib/ddr/models/version.rb
CHANGED
data/lib/ddr/utils.rb
CHANGED
@@ -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.
|
98
|
+
objs.each { |obj| pids << obj.id }
|
99
99
|
if model.present?
|
100
|
-
objs.each { |obj| pids.delete(obj.
|
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.
|
104
|
+
pids.delete(obj.id) unless obj == collection || obj.parent == collection
|
105
105
|
end
|
106
106
|
end
|
107
107
|
case pids.size
|