ddr-models 2.0.1 → 2.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -17
- data/app/models/collection.rb +1 -35
- data/ddr-models.gemspec +2 -1
- data/lib/ddr/actions.rb +1 -0
- data/lib/ddr/actions/virus_check.rb +28 -0
- data/lib/ddr/auth.rb +4 -0
- data/lib/ddr/auth/ability_definitions/datastream_ability_definitions.rb +7 -5
- data/lib/ddr/auth/grouper_gateway.rb +9 -1
- data/lib/ddr/auth/permissions.rb +2 -1
- data/lib/ddr/auth/role_based_access_controls_enforcement.rb +5 -5
- data/lib/ddr/auth/roles/role_types.rb +2 -1
- data/lib/ddr/datastreams.rb +2 -2
- data/lib/ddr/datastreams/administrative_metadata_datastream.rb +27 -14
- data/lib/ddr/datastreams/datastream_behavior.rb +13 -0
- data/lib/ddr/datastreams/fits_datastream.rb +88 -0
- data/lib/ddr/derivatives/png_generator.rb +2 -0
- data/lib/ddr/derivatives/ptif_generator.rb +2 -0
- data/lib/ddr/events/fixity_check_event.rb +2 -2
- data/lib/ddr/events/virus_check_event.rb +2 -14
- data/lib/ddr/index.rb +29 -0
- data/lib/ddr/index/abstract_query_result.rb +23 -0
- data/lib/ddr/index/connection.rb +17 -0
- data/lib/ddr/index/csv_query_result.rb +61 -0
- data/lib/ddr/index/document_builder.rb +9 -0
- data/lib/ddr/index/field.rb +23 -0
- data/lib/ddr/index/fields.rb +83 -0
- data/lib/ddr/index/filter.rb +48 -0
- data/lib/ddr/index/filters.rb +19 -0
- data/lib/ddr/index/legacy_license_fields.rb +14 -0
- data/lib/ddr/index/query.rb +35 -0
- data/lib/ddr/index/query_builder.rb +74 -0
- data/lib/ddr/index/query_clause.rb +52 -0
- data/lib/ddr/index/query_result.rb +70 -0
- data/lib/ddr/index/query_value.rb +16 -0
- data/lib/ddr/index/response.rb +13 -0
- data/lib/ddr/index/unique_key_field.rb +12 -0
- data/lib/ddr/index_fields.rb +7 -53
- data/lib/ddr/jobs.rb +1 -1
- data/lib/ddr/jobs/fits_file_characterization.rb +51 -0
- data/lib/ddr/managers.rb +1 -0
- data/lib/ddr/managers/technical_metadata_manager.rb +104 -0
- data/lib/ddr/models.rb +39 -23
- data/lib/ddr/models/base.rb +0 -2
- data/lib/ddr/models/describable.rb +1 -1
- data/lib/ddr/models/effective_license.rb +9 -0
- data/lib/ddr/models/engine.rb +13 -0
- data/lib/ddr/models/file_management.rb +157 -160
- data/lib/ddr/models/governable.rb +0 -4
- data/lib/ddr/models/has_admin_metadata.rb +80 -72
- data/lib/ddr/models/has_children.rb +1 -1
- data/lib/ddr/models/has_content.rb +18 -0
- data/lib/ddr/models/has_struct_metadata.rb +5 -1
- data/lib/ddr/models/indexing.rb +32 -20
- data/lib/ddr/models/inherited_license.rb +13 -0
- data/lib/ddr/models/license.rb +38 -0
- data/lib/ddr/models/solr_document.rb +195 -211
- data/lib/ddr/models/version.rb +1 -1
- data/lib/ddr/models/year_facet.rb +154 -0
- data/lib/ddr/utils.rb +13 -1
- data/lib/ddr/vocab/roles.rb +0 -10
- data/spec/controllers/including_role_based_access_controls_enforcement_spec.rb +4 -4
- data/spec/datastreams/fits_datastream_spec.rb +84 -0
- data/spec/fixtures/fits/document.xml +65 -0
- data/spec/fixtures/fits/image.xml +59 -0
- data/spec/index/filter_spec.rb +47 -0
- data/spec/index/filters_spec.rb +17 -0
- data/spec/index/query_spec.rb +19 -0
- data/spec/jobs/fits_file_characterization_spec.rb +52 -0
- data/spec/managers/technical_metadata_manager_spec.rb +140 -0
- data/spec/models/active_fedora_datastream_spec.rb +44 -0
- data/spec/models/collection_spec.rb +7 -12
- data/spec/models/component_spec.rb +3 -6
- data/spec/models/effective_license_spec.rb +49 -0
- data/spec/models/has_admin_metadata_spec.rb +143 -194
- data/spec/models/has_struct_metadata_spec.rb +2 -2
- data/spec/models/indexing_spec.rb +40 -0
- data/spec/models/solr_document_spec.rb +96 -37
- data/spec/models/year_facet_spec.rb +65 -0
- data/spec/spec_helper.rb +1 -7
- data/spec/support/shared_examples_for_ddr_models.rb +0 -2
- data/spec/support/shared_examples_for_has_content.rb +37 -3
- metadata +79 -32
- data/lib/ddr/datastreams/properties_datastream.rb +0 -25
- data/lib/ddr/jobs/migrate_legacy_authorization.rb +0 -23
- data/lib/ddr/models/has_properties.rb +0 -15
- data/lib/ddr/models/licensable.rb +0 -28
- data/spec/auth/legacy_authorization_spec.rb +0 -94
- data/spec/auth/legacy_roles_spec.rb +0 -32
- data/spec/jobs/migrate_legacy_authorization_spec.rb +0 -43
- data/spec/support/shared_examples_for_has_properties.rb +0 -5
- data/spec/support/shared_examples_for_licensable.rb +0 -15
@@ -3,7 +3,7 @@ module Ddr
|
|
3
3
|
module HasChildren
|
4
4
|
|
5
5
|
def first_child
|
6
|
-
ActiveFedora::Base.where(association_query(:children)).order("#{Ddr::
|
6
|
+
ActiveFedora::Base.where(association_query(:children)).order("#{Ddr::Index::Fields::LOCAL_ID} ASC").first
|
7
7
|
end
|
8
8
|
|
9
9
|
end
|
@@ -29,12 +29,21 @@ module Ddr
|
|
29
29
|
label: "Text extracted from the content file",
|
30
30
|
control_group: "M"
|
31
31
|
|
32
|
+
has_metadata \
|
33
|
+
name: Ddr::Datastreams::FITS,
|
34
|
+
type: Ddr::Datastreams::FitsDatastream,
|
35
|
+
versionable: true,
|
36
|
+
label: "FITS Output for content file",
|
37
|
+
control_group: "M"
|
38
|
+
|
32
39
|
has_attributes :original_filename, datastream: "adminMetadata", multiple: false
|
33
40
|
|
34
41
|
include FileManagement
|
35
42
|
|
36
43
|
around_save :update_derivatives, if: :content_changed?
|
37
44
|
|
45
|
+
around_save :characterize_file, if: [ :content_changed?, "Ddr::Models.characterize_files?" ]
|
46
|
+
|
38
47
|
after_add_file do
|
39
48
|
if file_to_add.original_name && file_to_add.dsid == "content"
|
40
49
|
self.original_filename = file_to_add.original_name
|
@@ -59,6 +68,10 @@ module Ddr
|
|
59
68
|
@derivatives ||= Ddr::Managers::DerivativesManager.new(self)
|
60
69
|
end
|
61
70
|
|
71
|
+
def techmd
|
72
|
+
@techmd ||= Ddr::Managers::TechnicalMetadataManager.new(self)
|
73
|
+
end
|
74
|
+
|
62
75
|
def content_size
|
63
76
|
content.external? ? content.file_size : content.dsSize
|
64
77
|
end
|
@@ -122,6 +135,11 @@ module Ddr
|
|
122
135
|
derivatives.update_derivatives(:later)
|
123
136
|
end
|
124
137
|
|
138
|
+
def characterize_file
|
139
|
+
yield
|
140
|
+
Resque.enqueue(Ddr::Jobs::FitsFileCharacterization, pid)
|
141
|
+
end
|
142
|
+
|
125
143
|
def default_content_type
|
126
144
|
"application/octet-stream"
|
127
145
|
end
|
@@ -26,11 +26,15 @@ module Ddr
|
|
26
26
|
structure
|
27
27
|
end
|
28
28
|
|
29
|
+
def multires_image_file_paths(type='default')
|
30
|
+
::SolrDocument.find(pid).multires_image_file_paths(type)
|
31
|
+
end
|
32
|
+
|
29
33
|
private
|
30
34
|
|
31
35
|
def find_children
|
32
36
|
query = association_query(:children)
|
33
|
-
sort = "#{Ddr::
|
37
|
+
sort = "#{Ddr::Index::Fields::LOCAL_ID} ASC, #{Ddr::Index::Fields::OBJECT_CREATE_DATE} ASC"
|
34
38
|
ActiveFedora::SolrService.query(query, sort: sort, rows: 999999)
|
35
39
|
end
|
36
40
|
|
data/lib/ddr/models/indexing.rb
CHANGED
@@ -2,7 +2,7 @@ module Ddr
|
|
2
2
|
module Models
|
3
3
|
module Indexing
|
4
4
|
|
5
|
-
include Ddr::
|
5
|
+
include Ddr::Index::Fields
|
6
6
|
|
7
7
|
def to_solr(solr_doc=Hash.new, opts={})
|
8
8
|
solr_doc = super(solr_doc, opts)
|
@@ -11,22 +11,34 @@ module Ddr
|
|
11
11
|
|
12
12
|
def index_fields
|
13
13
|
fields = {
|
14
|
-
|
15
|
-
INTERNAL_URI => internal_uri,
|
16
|
-
IDENTIFIER_ALL => all_identifiers,
|
17
|
-
WORKFLOW_STATE => workflow_state,
|
18
|
-
LOCAL_ID => local_id,
|
14
|
+
ACCESS_ROLE => roles.to_json,
|
19
15
|
ADMIN_SET => admin_set,
|
16
|
+
BOX_NUMBER_FACET => desc_metadata_values('box_number'),
|
17
|
+
CREATOR_FACET => creator,
|
18
|
+
DATE_FACET => date,
|
19
|
+
DATE_SORT => date_sort,
|
20
|
+
DEPOSITOR => depositor,
|
20
21
|
DISPLAY_FORMAT => display_format,
|
22
|
+
DOI => adminMetadata.doi,
|
23
|
+
IDENTIFIER_ALL => all_identifiers,
|
24
|
+
INTERNAL_URI => internal_uri,
|
25
|
+
LICENSE => license,
|
26
|
+
LICENSE_DESCRIPTION => rightsMetadata.license.description.first,
|
27
|
+
LICENSE_TITLE => rightsMetadata.license.title.first,
|
28
|
+
LICENSE_URL => rightsMetadata.license.url.first,
|
29
|
+
LOCAL_ID => local_id,
|
21
30
|
PERMANENT_ID => permanent_id,
|
22
31
|
PERMANENT_URL => permanent_url,
|
23
|
-
ACCESS_ROLE => roles.to_json,
|
24
|
-
RESOURCE_ROLE => roles.in_resource_scope.agents,
|
25
32
|
POLICY_ROLE => roles.in_policy_scope.agents,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
PUBLISHER_FACET => publisher,
|
34
|
+
RESEARCH_HELP_CONTACT => research_help_contact,
|
35
|
+
RESOURCE_ROLE => roles.in_resource_scope.agents,
|
36
|
+
SERIES_FACET => desc_metadata_values('series'),
|
37
|
+
SPATIAL_FACET => desc_metadata_values('spatial'),
|
38
|
+
TITLE => title_display,
|
39
|
+
TYPE_FACET => type,
|
40
|
+
WORKFLOW_STATE => workflow_state,
|
41
|
+
YEAR_FACET => year_facet,
|
30
42
|
}
|
31
43
|
if respond_to? :fixity_checks
|
32
44
|
last_fixity_check = fixity_checks.last
|
@@ -36,11 +48,6 @@ module Ddr
|
|
36
48
|
last_virus_check = virus_checks.last
|
37
49
|
fields.merge!(last_virus_check.to_solr) if last_virus_check
|
38
50
|
end
|
39
|
-
if respond_to? :license
|
40
|
-
fields[LICENSE_DESCRIPTION] = license_description
|
41
|
-
fields[LICENSE_TITLE] = license_title
|
42
|
-
fields[LICENSE_URL] = license_url
|
43
|
-
end
|
44
51
|
if has_content?
|
45
52
|
fields[CONTENT_CONTROL_GROUP] = content.controlGroup
|
46
53
|
fields[CONTENT_SIZE] = content_size
|
@@ -48,6 +55,7 @@ module Ddr
|
|
48
55
|
fields[MEDIA_TYPE] = content_type
|
49
56
|
fields[MEDIA_MAJOR_TYPE] = content_major_type
|
50
57
|
fields[MEDIA_SUB_TYPE] = content_sub_type
|
58
|
+
fields.merge! techmd.index_fields
|
51
59
|
end
|
52
60
|
if has_multires_image?
|
53
61
|
fields[MULTIRES_IMAGE_FILE_PATH] = multires_image_file_path
|
@@ -62,9 +70,9 @@ module Ddr
|
|
62
70
|
fields[COLLECTION_URI] = collection_uri
|
63
71
|
end
|
64
72
|
if is_a? Collection
|
65
|
-
fields[DEFAULT_LICENSE_DESCRIPTION] =
|
66
|
-
fields[DEFAULT_LICENSE_TITLE] =
|
67
|
-
fields[DEFAULT_LICENSE_URL] =
|
73
|
+
fields[DEFAULT_LICENSE_DESCRIPTION] = defaultRights.license.description.first
|
74
|
+
fields[DEFAULT_LICENSE_TITLE] = defaultRights.license.title.first
|
75
|
+
fields[DEFAULT_LICENSE_URL] = defaultRights.license.url.first
|
68
76
|
fields[ADMIN_SET_FACET] = admin_set_facet
|
69
77
|
fields[COLLECTION_FACET] = collection_facet
|
70
78
|
end
|
@@ -106,6 +114,10 @@ module Ddr
|
|
106
114
|
date.first
|
107
115
|
end
|
108
116
|
|
117
|
+
def year_facet
|
118
|
+
YearFacet.call(self)
|
119
|
+
end
|
120
|
+
|
109
121
|
end
|
110
122
|
end
|
111
123
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Ddr::Models
|
2
|
+
class InheritedLicense
|
3
|
+
|
4
|
+
def self.call(obj)
|
5
|
+
if obj.respond_to?(:parent) && obj.parent
|
6
|
+
EffectiveLicense.call obj.parent
|
7
|
+
elsif obj.admin_policy && (obj.admin_policy != obj)
|
8
|
+
EffectiveLicense.call obj.admin_policy
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
require "ddr_aux/client"
|
3
|
+
|
4
|
+
module Ddr::Models
|
5
|
+
class License < SimpleDelegator
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def get(url)
|
9
|
+
new DdrAux::Client.find_license(url: url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def all
|
13
|
+
DdrAux::Client.licenses.map { |l| new(l) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(obj)
|
17
|
+
if obj.license
|
18
|
+
l = get obj.license
|
19
|
+
l[:licensed] = obj.pid
|
20
|
+
l
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(args={})
|
26
|
+
super OpenStruct.new(args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_json
|
30
|
+
to_h.to_json
|
31
|
+
end
|
32
|
+
|
33
|
+
def ==(other)
|
34
|
+
other.is_a?(self.class) && other.__getobj__ == __getobj__
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -1,275 +1,259 @@
|
|
1
1
|
require 'json'
|
2
2
|
|
3
|
-
module Ddr
|
4
|
-
module
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
3
|
+
module Ddr::Models
|
4
|
+
module SolrDocument
|
5
|
+
extend ActiveSupport::Concern
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
def to_partial_path
|
13
|
-
'document'
|
14
|
-
end
|
15
|
-
|
16
|
-
def safe_id
|
17
|
-
id.sub(/:/, "-")
|
18
|
-
end
|
19
|
-
|
20
|
-
def admin_set
|
21
|
-
get(Ddr::IndexFields::ADMIN_SET)
|
22
|
-
end
|
23
|
-
|
24
|
-
def local_id
|
25
|
-
get(Ddr::IndexFields::LOCAL_ID)
|
26
|
-
end
|
27
|
-
|
28
|
-
def active_fedora_model
|
29
|
-
get(Ddr::IndexFields::ACTIVE_FEDORA_MODEL)
|
30
|
-
end
|
31
|
-
|
32
|
-
def internal_uri
|
33
|
-
get(Ddr::IndexFields::INTERNAL_URI)
|
34
|
-
end
|
35
|
-
|
36
|
-
def object_profile
|
37
|
-
@object_profile ||= get_json(Ddr::IndexFields::OBJECT_PROFILE)
|
38
|
-
end
|
7
|
+
included do
|
8
|
+
alias_method :pid, :id
|
9
|
+
end
|
39
10
|
|
40
|
-
|
41
|
-
object_profile["objState"]
|
42
|
-
end
|
11
|
+
class NotFound < Error; end
|
43
12
|
|
44
|
-
|
45
|
-
|
13
|
+
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) }
|
17
|
+
if doc = query.docs.first
|
18
|
+
return doc
|
19
|
+
end
|
20
|
+
raise NotFound, "SolrDocument not found for \"#{pid_or_uri}\"."
|
46
21
|
end
|
22
|
+
end
|
47
23
|
|
48
|
-
|
49
|
-
|
50
|
-
|
24
|
+
def inspect
|
25
|
+
"#<#{self.class.name} id=#{id.inspect}>"
|
26
|
+
end
|
51
27
|
|
52
|
-
|
53
|
-
|
28
|
+
def method_missing(name, *args, &block)
|
29
|
+
if args.empty? && !block
|
30
|
+
begin
|
31
|
+
field = Ddr::Index::Fields.get(name)
|
32
|
+
rescue NameError
|
33
|
+
# pass
|
34
|
+
else
|
35
|
+
# Preserves the default behavior of the deprecated method
|
36
|
+
# Blacklight::Solr::Document#get, which this procedure
|
37
|
+
# effectively replaces.
|
38
|
+
val = self[field]
|
39
|
+
return val.is_a?(Array) ? val.join(", ") : val
|
40
|
+
end
|
54
41
|
end
|
42
|
+
super
|
43
|
+
end
|
55
44
|
|
56
|
-
|
57
|
-
|
58
|
-
|
45
|
+
def to_partial_path
|
46
|
+
'document'
|
47
|
+
end
|
59
48
|
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
def safe_id
|
50
|
+
id.sub(/:/, "-")
|
51
|
+
end
|
63
52
|
|
64
|
-
|
65
|
-
|
66
|
-
|
53
|
+
def object_profile
|
54
|
+
@object_profile ||= get_json(Ddr::Index::Fields::OBJECT_PROFILE)
|
55
|
+
end
|
67
56
|
|
68
|
-
|
69
|
-
|
70
|
-
|
57
|
+
def object_state
|
58
|
+
object_profile["objState"]
|
59
|
+
end
|
71
60
|
|
72
|
-
|
73
|
-
|
74
|
-
|
61
|
+
def object_create_date
|
62
|
+
parse_date(object_profile["objCreateDate"])
|
63
|
+
end
|
75
64
|
|
76
|
-
|
77
|
-
|
78
|
-
|
65
|
+
def object_modified_date
|
66
|
+
parse_date(object_profile["objLastModDate"])
|
67
|
+
end
|
79
68
|
|
80
|
-
|
81
|
-
|
82
|
-
|
69
|
+
def last_fixity_check_on
|
70
|
+
get_date(Ddr::Index::Fields::LAST_FIXITY_CHECK_ON)
|
71
|
+
end
|
83
72
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
73
|
+
def last_virus_check_on
|
74
|
+
get_date(Ddr::Index::Fields::LAST_VIRUS_CHECK_ON)
|
75
|
+
end
|
88
76
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
self.class.new(ActiveFedora::SolrService.query(query).first)
|
93
|
-
end
|
94
|
-
end
|
77
|
+
def datastreams
|
78
|
+
object_profile["datastreams"]
|
79
|
+
end
|
95
80
|
|
96
|
-
|
97
|
-
|
98
|
-
|
81
|
+
def has_datastream?(dsID)
|
82
|
+
datastreams[dsID].present?
|
83
|
+
end
|
99
84
|
|
100
|
-
|
101
|
-
|
102
|
-
|
85
|
+
def has_admin_policy?
|
86
|
+
admin_policy_uri.present?
|
87
|
+
end
|
103
88
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
alias_method :title_display, :title # duck-type Ddr::Models::Base
|
89
|
+
def admin_policy_uri
|
90
|
+
is_governed_by
|
91
|
+
end
|
108
92
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
93
|
+
def admin_policy_pid
|
94
|
+
uri = admin_policy_uri
|
95
|
+
uri &&= ActiveFedora::Base.pid_from_uri(uri)
|
96
|
+
end
|
113
97
|
|
114
|
-
|
115
|
-
|
98
|
+
def admin_policy
|
99
|
+
if has_admin_policy?
|
100
|
+
self.class.find(admin_policy_uri)
|
116
101
|
end
|
102
|
+
end
|
117
103
|
|
118
|
-
|
119
|
-
|
120
|
-
|
104
|
+
def has_children?
|
105
|
+
ActiveFedora::SolrService.class_from_solr_document(self).reflect_on_association(:children).present?
|
106
|
+
end
|
121
107
|
|
122
|
-
|
123
|
-
|
124
|
-
|
108
|
+
def label
|
109
|
+
object_profile["objLabel"]
|
110
|
+
end
|
125
111
|
|
126
|
-
|
127
|
-
|
128
|
-
|
112
|
+
def title_display
|
113
|
+
title
|
114
|
+
end
|
129
115
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
alias_method :content_type, :content_mime_type
|
116
|
+
def identifier
|
117
|
+
# We want the multivalued version here
|
118
|
+
self[ActiveFedora::SolrService.solr_name(:identifier, :stored_searchable, type: :text)]
|
119
|
+
end
|
135
120
|
|
136
|
-
|
137
|
-
|
138
|
-
|
121
|
+
def source
|
122
|
+
self[ActiveFedora::SolrService.solr_name(:source, :stored_searchable, type: :text)]
|
123
|
+
end
|
139
124
|
|
140
|
-
|
141
|
-
|
142
|
-
|
125
|
+
def has_thumbnail?
|
126
|
+
has_datastream?(Ddr::Datastreams::THUMBNAIL)
|
127
|
+
end
|
143
128
|
|
144
|
-
|
145
|
-
|
146
|
-
|
129
|
+
def has_content?
|
130
|
+
has_datastream?(Ddr::Datastreams::CONTENT)
|
131
|
+
end
|
147
132
|
|
148
|
-
|
149
|
-
|
150
|
-
|
133
|
+
def content_ds
|
134
|
+
datastreams[Ddr::Datastreams::CONTENT]
|
135
|
+
end
|
151
136
|
|
152
|
-
|
153
|
-
|
154
|
-
|
137
|
+
def content_mime_type
|
138
|
+
content_ds["dsMIME"] rescue nil
|
139
|
+
end
|
140
|
+
# For duck-typing with Ddr::Models::HasContent
|
141
|
+
alias_method :content_type, :content_mime_type
|
155
142
|
|
156
|
-
|
157
|
-
|
158
|
-
|
143
|
+
def content_checksum
|
144
|
+
content_ds["dsChecksum"] rescue nil
|
145
|
+
end
|
159
146
|
|
160
|
-
|
161
|
-
|
162
|
-
|
147
|
+
def targets
|
148
|
+
@targets ||= ActiveFedora::SolrService.query(targets_query)
|
149
|
+
end
|
163
150
|
|
164
|
-
|
165
|
-
|
166
|
-
|
151
|
+
def targets_count
|
152
|
+
@targets_count ||= ActiveFedora::SolrService.count(targets_query)
|
153
|
+
end
|
167
154
|
|
168
|
-
|
169
|
-
|
170
|
-
|
155
|
+
def has_target?
|
156
|
+
targets_count > 0
|
157
|
+
end
|
171
158
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
results = ActiveFedora::SolrService.query(query)
|
176
|
-
doc = results.map { |result| ::SolrDocument.new(result) }.first
|
177
|
-
{ title: doc.get(Ddr::IndexFields::DEFAULT_LICENSE_TITLE),
|
178
|
-
description: doc.get(Ddr::IndexFields::DEFAULT_LICENSE_DESCRIPTION),
|
179
|
-
url: doc.get(Ddr::IndexFields::DEFAULT_LICENSE_URL) }
|
180
|
-
end
|
181
|
-
end
|
159
|
+
def association(name)
|
160
|
+
get_pid(ActiveFedora::SolrService.solr_name(name, :symbol))
|
161
|
+
end
|
182
162
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
description: get(Ddr::IndexFields::LICENSE_DESCRIPTION),
|
187
|
-
url: get(Ddr::IndexFields::LICENSE_URL) }
|
188
|
-
end
|
189
|
-
end
|
163
|
+
def controller_name
|
164
|
+
active_fedora_model.tableize
|
165
|
+
end
|
190
166
|
|
191
|
-
|
192
|
-
|
193
|
-
|
167
|
+
def effective_license
|
168
|
+
@effective_license ||= EffectiveLicense.call(self)
|
169
|
+
end
|
194
170
|
|
195
|
-
|
196
|
-
|
197
|
-
|
171
|
+
def roles
|
172
|
+
@roles ||= Ddr::Auth::Roles::DetachedRoleSet.from_json(access_role)
|
173
|
+
end
|
198
174
|
|
199
|
-
|
200
|
-
|
201
|
-
|
175
|
+
def struct_maps
|
176
|
+
JSON.parse(fetch(Ddr::Index::Fields::STRUCT_MAPS))
|
177
|
+
rescue
|
178
|
+
{}
|
179
|
+
end
|
202
180
|
|
203
|
-
|
204
|
-
|
205
|
-
|
181
|
+
def struct_map(type='default')
|
182
|
+
struct_maps.present? ? struct_maps.fetch(type) : nil
|
183
|
+
end
|
206
184
|
|
207
|
-
|
208
|
-
|
209
|
-
|
185
|
+
def effective_permissions(agents)
|
186
|
+
Ddr::Auth::EffectivePermissions.call(self, agents)
|
187
|
+
end
|
210
188
|
|
211
|
-
|
212
|
-
|
213
|
-
|
189
|
+
def research_help
|
190
|
+
research_help_contact = self[Ddr::Index::Fields::RESEARCH_HELP_CONTACT] || inherited_research_help_contact
|
191
|
+
Ddr::Contacts.get(research_help_contact) if research_help_contact
|
192
|
+
end
|
214
193
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
{}
|
219
|
-
end
|
194
|
+
def parent_uri
|
195
|
+
is_part_of || is_member_of_collection
|
196
|
+
end
|
220
197
|
|
221
|
-
|
222
|
-
|
223
|
-
|
198
|
+
def has_parent?
|
199
|
+
parent_uri.present?
|
200
|
+
end
|
224
201
|
|
225
|
-
|
226
|
-
|
202
|
+
def parent
|
203
|
+
if has_parent?
|
204
|
+
self.class.find(parent_uri)
|
227
205
|
end
|
206
|
+
end
|
228
207
|
|
229
|
-
|
230
|
-
|
231
|
-
|
208
|
+
def multires_image_file_paths(type='default')
|
209
|
+
struct_map_docs(type).map { |doc| doc.multires_image_file_path }.compact
|
210
|
+
end
|
232
211
|
|
233
|
-
|
234
|
-
research_help_contact = self[Ddr::IndexFields::RESEARCH_HELP_CONTACT] || inherited_research_help_contact
|
235
|
-
Ddr::Contacts.get(research_help_contact) if research_help_contact
|
236
|
-
end
|
212
|
+
private
|
237
213
|
|
238
|
-
|
214
|
+
def targets_query
|
215
|
+
"#{Ddr::Index::Fields::IS_EXTERNAL_TARGET_FOR}:#{internal_uri_for_query}"
|
216
|
+
end
|
239
217
|
|
240
|
-
|
241
|
-
|
242
|
-
|
218
|
+
def internal_uri_for_query
|
219
|
+
ActiveFedora::SolrService.escape_uri_for_query(internal_uri)
|
220
|
+
end
|
243
221
|
|
244
|
-
|
245
|
-
|
246
|
-
|
222
|
+
def get_date(field)
|
223
|
+
parse_date(self[field])
|
224
|
+
end
|
247
225
|
|
248
|
-
|
249
|
-
|
250
|
-
|
226
|
+
def get_json(field)
|
227
|
+
JSON.parse Array(self[field]).first
|
228
|
+
end
|
251
229
|
|
252
|
-
|
253
|
-
|
254
|
-
|
230
|
+
def parse_date(date)
|
231
|
+
Time.parse(date).localtime if date
|
232
|
+
end
|
255
233
|
|
256
|
-
|
257
|
-
|
258
|
-
|
234
|
+
def get_pid(field)
|
235
|
+
ActiveFedora::Base.pid_from_uri(self[field]) rescue nil
|
236
|
+
end
|
259
237
|
|
260
|
-
|
261
|
-
|
238
|
+
def inherited_research_help_contact
|
239
|
+
if doc = admin_policy
|
240
|
+
doc.research_help_contact
|
262
241
|
end
|
242
|
+
end
|
263
243
|
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
results = ActiveFedora::SolrService.query(query)
|
268
|
-
doc = results.map { |result| ::SolrDocument.new(result) }.first
|
269
|
-
doc[Ddr::IndexFields::RESEARCH_HELP_CONTACT]
|
270
|
-
end
|
271
|
-
end
|
244
|
+
def struct_map_docs(type='default')
|
245
|
+
struct_map_pids(type).map { |pid| self.class.find(pid) }.compact
|
246
|
+
end
|
272
247
|
|
248
|
+
# For simplicity, initial implementation returns PID's only from top-level
|
249
|
+
# (i.e., not nested) div's. This is done since we have not clarified what
|
250
|
+
# an _ordered_ list of PID's should look like if struct map contains nested
|
251
|
+
# div's.
|
252
|
+
def struct_map_pids(type='default')
|
253
|
+
struct_map(type)['divs'].map { |d| d['fptrs'].present? ? d['fptrs'].first : nil}.compact
|
254
|
+
rescue
|
255
|
+
[]
|
273
256
|
end
|
257
|
+
|
274
258
|
end
|
275
259
|
end
|