dor-services 6.8.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/config/config_defaults.yml +0 -27
- data/config/dev_console_env.rb.example +0 -17
- data/lib/dor-services.rb +9 -73
- data/lib/dor/config.rb +1 -30
- data/lib/dor/datastreams/content_metadata_ds.rb +8 -0
- data/lib/dor/datastreams/desc_metadata_ds.rb +19 -0
- data/lib/dor/datastreams/identity_metadata_ds.rb +65 -0
- data/lib/dor/datastreams/rights_metadata_ds.rb +14 -2
- data/lib/dor/datastreams/workflow_definition_ds.rb +1 -1
- data/lib/dor/datastreams/workflow_ds.rb +0 -15
- data/lib/dor/indexers/identifiable_indexer.rb +8 -4
- data/lib/dor/indexers/releasable_indexer.rb +7 -1
- data/lib/dor/models/abstract.rb +143 -8
- data/lib/dor/models/admin_policy_object.rb +0 -3
- data/lib/dor/models/collection.rb +0 -2
- data/lib/dor/models/concerns/embargoable.rb +7 -60
- data/lib/dor/models/etd.rb +100 -0
- data/lib/dor/models/item.rb +12 -28
- data/lib/dor/models/part.rb +18 -0
- data/lib/dor/models/set.rb +0 -2
- data/lib/dor/services/collection_service.rb +36 -0
- data/lib/dor/services/embargo_service.rb +93 -0
- data/lib/dor/services/ontology.rb +0 -18
- data/lib/dor/services/public_desc_metadata_service.rb +7 -11
- data/lib/dor/services/search_service.rb +0 -40
- data/lib/dor/version.rb +1 -1
- data/lib/dor/workflow/document.rb +0 -7
- metadata +15 -78
- data/lib/dor/models/concerns/assembleable.rb +0 -18
- data/lib/dor/models/concerns/contentable.rb +0 -185
- data/lib/dor/models/concerns/describable.rb +0 -82
- data/lib/dor/models/concerns/eventable.rb +0 -18
- data/lib/dor/models/concerns/geoable.rb +0 -14
- data/lib/dor/models/concerns/governable.rb +0 -101
- data/lib/dor/models/concerns/identifiable.rb +0 -172
- data/lib/dor/models/concerns/itemizable.rb +0 -42
- data/lib/dor/models/concerns/preservable.rb +0 -46
- data/lib/dor/models/concerns/processable.rb +0 -86
- data/lib/dor/models/concerns/publishable.rb +0 -76
- data/lib/dor/models/concerns/releaseable.rb +0 -118
- data/lib/dor/models/concerns/rightsable.rb +0 -25
- data/lib/dor/models/concerns/shelvable.rb +0 -15
- data/lib/dor/models/concerns/versionable.rb +0 -72
- data/lib/dor/services/ability.rb +0 -77
- data/lib/dor/services/cleanup_reset_service.rb +0 -103
- data/lib/dor/services/datastream_builder.rb +0 -96
- data/lib/dor/services/decommission_service.rb +0 -31
- data/lib/dor/services/digital_stacks_service.rb +0 -125
- data/lib/dor/services/dublin_core_service.rb +0 -45
- data/lib/dor/services/file_metadata_merge_service.rb +0 -71
- data/lib/dor/services/indexing_service.rb +0 -131
- data/lib/dor/services/merge_service.rb +0 -105
- data/lib/dor/services/public_xml_service.rb +0 -116
- data/lib/dor/services/publish_metadata_service.rb +0 -99
- data/lib/dor/services/reset_workspace_service.rb +0 -27
- data/lib/dor/services/sdr_ingest_service.rb +0 -172
- data/lib/dor/services/secondary_file_name_service.rb +0 -10
- data/lib/dor/services/shelving_service.rb +0 -69
- data/lib/dor/services/technical_metadata_service.rb +0 -232
- data/lib/dor/services/version_service.rb +0 -84
- data/lib/dor/utils/sdr_client.rb +0 -94
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dor
|
4
|
-
module Assembleable
|
5
|
-
extend Deprecation
|
6
|
-
self.deprecation_horizon = 'dor-services version 7.0.0'
|
7
|
-
|
8
|
-
def initialize_workspace(source = nil)
|
9
|
-
druid = DruidTools::Druid.new(pid, Config.stacks.local_workspace_root)
|
10
|
-
if source.nil?
|
11
|
-
druid.mkdir
|
12
|
-
else
|
13
|
-
druid.mkdir_with_final_link(source)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
deprecation_deprecate initialize_workspace: 'Use Dor::Services::Client.object(object_identifier).workspace.create(source:) instead'
|
17
|
-
end
|
18
|
-
end
|
@@ -1,185 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dor
|
4
|
-
module Contentable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
extend Deprecation
|
7
|
-
self.deprecation_horizon = 'dor-services version 7.0.0'
|
8
|
-
|
9
|
-
# add a file to a resource, not to be confused with add a resource to an object
|
10
|
-
def add_file(file, resource, file_name, mime_type = nil, publish = 'no', shelve = 'no', preserve = 'no')
|
11
|
-
xml = datastreams['contentMetadata'].ng_xml
|
12
|
-
# make sure the resource exists
|
13
|
-
raise 'resource doesnt exist.' if xml.search('//resource[@id=\'' + resource + '\']').length == 0
|
14
|
-
|
15
|
-
sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, auth_methods: ['publickey'])
|
16
|
-
druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
|
17
|
-
location = druid_tools.path(file_name)
|
18
|
-
oldlocation = location.gsub('/' + pid.gsub('druid:', ''), '')
|
19
|
-
md5 = Digest::MD5.file(file.path).hexdigest
|
20
|
-
sha1 = Digest::SHA1.file(file.path).hexdigest
|
21
|
-
size = File.size?(file.path)
|
22
|
-
# update contentmd
|
23
|
-
file_hash = { name: file_name, md5: md5, publish: publish, shelve: shelve, preserve: preserve, size: size.to_s, sha1: sha1, mime_type: mime_type }
|
24
|
-
begin
|
25
|
-
sftp.stat!(location.gsub(file_name, ''))
|
26
|
-
begin
|
27
|
-
sftp.stat!(location)
|
28
|
-
raise "The file #{file_name} already exists!"
|
29
|
-
rescue Net::SFTP::StatusException
|
30
|
-
sftp.upload!(file.path, location)
|
31
|
-
contentMetadata.add_file file_hash, resource
|
32
|
-
end
|
33
|
-
rescue Net::SFTP::StatusException
|
34
|
-
# directory layout doesn't match the new style, so use the old style.
|
35
|
-
begin
|
36
|
-
sftp.stat!(oldlocation)
|
37
|
-
raise "The file #{file_name} already exists!"
|
38
|
-
rescue Net::SFTP::StatusException
|
39
|
-
# file doesn't already exist, which is good. Add it
|
40
|
-
sftp.upload!(file.path, oldlocation)
|
41
|
-
contentMetadata.add_file file_hash, resource
|
42
|
-
end
|
43
|
-
end
|
44
|
-
# can only arrive at this point if a non status exception occurred.
|
45
|
-
end
|
46
|
-
deprecation_deprecate add_file: 'will be removed without replacement'
|
47
|
-
|
48
|
-
def replace_file(file, file_name)
|
49
|
-
sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, auth_methods: ['publickey'])
|
50
|
-
item = Dor.find(pid)
|
51
|
-
druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
|
52
|
-
location = druid_tools.path(file_name)
|
53
|
-
oldlocation = location.gsub('/' + pid.gsub('druid:', ''), '')
|
54
|
-
md5 = Digest::MD5.file(file.path).hexdigest
|
55
|
-
sha1 = Digest::SHA1.file(file.path).hexdigest
|
56
|
-
size = File.size?(file.path)
|
57
|
-
# update contentmd
|
58
|
-
file_hash = { name: file_name, md5: md5, size: size.to_s, sha1: sha1 }
|
59
|
-
begin
|
60
|
-
sftp.stat!(location)
|
61
|
-
sftp.upload!(file.path, location)
|
62
|
-
# this doesnt allow renaming files
|
63
|
-
item.contentMetadata.update_file(file_hash, file_name)
|
64
|
-
rescue StandardError
|
65
|
-
sftp.upload!(file.path, oldlocation)
|
66
|
-
item.contentMetadata.update_file(file_hash, file_name)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
deprecation_deprecate replace_file: 'will be removed without replacement'
|
70
|
-
|
71
|
-
def get_preserved_file(file, version)
|
72
|
-
Sdr::Client.get_preserved_file_content(pid, file, version)
|
73
|
-
end
|
74
|
-
deprecation_deprecate get_preserved_file: 'Use Dor::Services::Client.object(object_identifier).files.preserved_content(filename:, version:) instead'
|
75
|
-
|
76
|
-
def get_file(file)
|
77
|
-
druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
|
78
|
-
location = druid_tools.path(file)
|
79
|
-
oldlocation = location.gsub('/' + file, '').gsub('/' + pid.gsub('druid:', ''), '') + '/' + file
|
80
|
-
sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, auth_methods: ['publickey'])
|
81
|
-
begin
|
82
|
-
data = sftp.download!(location)
|
83
|
-
rescue StandardError
|
84
|
-
data = sftp.download!(oldlocation)
|
85
|
-
end
|
86
|
-
data
|
87
|
-
end
|
88
|
-
deprecation_deprecate get_file: 'Use Dor::Services::Client.object(object_identifier).files.retrieve(filename:) instead'
|
89
|
-
|
90
|
-
# @param [String] filename
|
91
|
-
def remove_file(filename)
|
92
|
-
druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
|
93
|
-
location = druid_tools.path(filename)
|
94
|
-
oldlocation = location.gsub('/' + pid.gsub('druid:', ''), '')
|
95
|
-
sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, auth_methods: ['publickey'])
|
96
|
-
begin
|
97
|
-
sftp.remove!(location)
|
98
|
-
rescue StandardError
|
99
|
-
# if the file doesnt exist, that is ok, not all files will be present in the workspace
|
100
|
-
begin
|
101
|
-
sftp.remove!(oldlocation)
|
102
|
-
rescue Net::SFTP::StatusException
|
103
|
-
end
|
104
|
-
end
|
105
|
-
contentMetadata.remove_file filename
|
106
|
-
end
|
107
|
-
deprecation_deprecate remove_file: 'will be removed without replacement'
|
108
|
-
|
109
|
-
# @param [String] old_name
|
110
|
-
# @param [String] new_name
|
111
|
-
def rename_file(old_name, new_name)
|
112
|
-
druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
|
113
|
-
location = druid_tools.path(old_name)
|
114
|
-
oldlocation = location.gsub('/' + pid.gsub('druid:', ''), '')
|
115
|
-
sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, auth_methods: ['publickey'])
|
116
|
-
begin
|
117
|
-
sftp.rename!(location, location.gsub(old_name, new_name))
|
118
|
-
rescue StandardError
|
119
|
-
sftp.rename!(oldlocation, oldlocation.gsub(old_name, new_name))
|
120
|
-
end
|
121
|
-
contentMetadata.rename_file(old_name, new_name)
|
122
|
-
end
|
123
|
-
deprecation_deprecate rename_file: 'will be removed without replacement'
|
124
|
-
|
125
|
-
# @param [String] resource_name ID of the resource elememnt
|
126
|
-
def remove_resource(resource_name)
|
127
|
-
# run delete for all of the files in the resource
|
128
|
-
contentMetadata.ng_xml.search('//resource[@id=\'' + resource_name + '\']/file').each do |file|
|
129
|
-
remove_file(file['id'])
|
130
|
-
end
|
131
|
-
# remove the resource record from the metadata and renumber the resource sequence
|
132
|
-
contentMetadata.remove_resource resource_name
|
133
|
-
end
|
134
|
-
deprecation_deprecate remove_resource: 'will be removed without replacement'
|
135
|
-
|
136
|
-
# list files in the workspace
|
137
|
-
# @return [Array] workspace files
|
138
|
-
def list_files
|
139
|
-
filename = 'none'
|
140
|
-
files = []
|
141
|
-
sftp = Net::SFTP.start(Config.content.content_server, Config.content.content_user, auth_methods: ['publickey'])
|
142
|
-
druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
|
143
|
-
location = druid_tools.path(filename).gsub(filename, '')
|
144
|
-
oldlocation = location.gsub('/' + pid.gsub('druid:', ''), '')
|
145
|
-
begin
|
146
|
-
sftp.dir.entries(location, '*') do |file|
|
147
|
-
files << file.name
|
148
|
-
end
|
149
|
-
rescue StandardError
|
150
|
-
begin
|
151
|
-
sftp.dir.glob(oldlocation, '*') do |file|
|
152
|
-
files << file.name
|
153
|
-
end
|
154
|
-
rescue Net::SFTP::StatusException
|
155
|
-
return files
|
156
|
-
end
|
157
|
-
end
|
158
|
-
files
|
159
|
-
end
|
160
|
-
deprecation_deprecate list_files: 'Use Dor::Services::Client.object(object_identifier).files.list instead'
|
161
|
-
|
162
|
-
# @param [String] filename
|
163
|
-
# @return [Boolean] whether the file in question is present in the object's workspace
|
164
|
-
def is_file_in_workspace?(filename)
|
165
|
-
druid_obj = DruidTools::Druid.new(pid, Dor::Config.stacks.local_workspace_root)
|
166
|
-
!druid_obj.find_content(filename).nil?
|
167
|
-
end
|
168
|
-
deprecation_deprecate is_file_in_workspace?: 'will be removed without replacement'
|
169
|
-
|
170
|
-
# Clears RELS-EXT relationships, sets the isGovernedBy relationship to the SDR Graveyard APO
|
171
|
-
# @param [String] tag optional String of text that is concatenated to the identityMetadata/tag "Decommissioned : "
|
172
|
-
def decommission(tag)
|
173
|
-
DecommissionService.new(self).decommission(tag)
|
174
|
-
end
|
175
|
-
deprecation_deprecate decommission: 'Use DecommissionService#decommission instead'
|
176
|
-
|
177
|
-
# Adds a RELS-EXT constituent relationship to the given druid
|
178
|
-
# @param [String] druid the parent druid of the constituent relationship
|
179
|
-
# e.g.: <fedora:isConstituentOf rdf:resource="info:fedora/druid:hj097bm8879" />
|
180
|
-
def add_constituent(druid)
|
181
|
-
add_relationship :is_constituent_of, ActiveFedora::Base.find(druid)
|
182
|
-
end
|
183
|
-
deprecation_deprecate add_constituent: 'Use add_relationship :is_constituent_of instead'
|
184
|
-
end
|
185
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dor
|
4
|
-
module Describable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
extend Deprecation
|
7
|
-
self.deprecation_horizon = 'dor-services version 7.0.0'
|
8
|
-
|
9
|
-
included do
|
10
|
-
has_metadata name: 'descMetadata', type: Dor::DescMetadataDS, label: 'Descriptive Metadata', control_group: 'M'
|
11
|
-
end
|
12
|
-
|
13
|
-
require 'stanford-mods'
|
14
|
-
|
15
|
-
# intended for read-access, "as SearchWorks would see it", mostly for to_solr()
|
16
|
-
# @param [Nokogiri::XML::Document] content Nokogiri descMetadata document (overriding internal data)
|
17
|
-
# @param [boolean] ns_aware namespace awareness toggle for from_nk_node()
|
18
|
-
def stanford_mods(content = nil, ns_aware = true)
|
19
|
-
@stanford_mods ||= begin
|
20
|
-
m = Stanford::Mods::Record.new
|
21
|
-
desc = content.nil? ? descMetadata.ng_xml : content
|
22
|
-
m.from_nk_node(desc.root, ns_aware)
|
23
|
-
m
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def fetch_descMetadata_datastream
|
28
|
-
candidates = datastreams['identityMetadata'].otherId.collect(&:to_s)
|
29
|
-
metadata_id = Dor::MetadataService.resolvable(candidates).first
|
30
|
-
metadata_id.nil? ? nil : Dor::MetadataService.fetch(metadata_id.to_s)
|
31
|
-
end
|
32
|
-
|
33
|
-
def build_descMetadata_datastream(ds)
|
34
|
-
content = fetch_descMetadata_datastream
|
35
|
-
return nil if content.nil?
|
36
|
-
|
37
|
-
ds.dsLabel = 'Descriptive Metadata'
|
38
|
-
ds.ng_xml = Nokogiri::XML(content)
|
39
|
-
ds.ng_xml.normalize_text!
|
40
|
-
ds.content = ds.ng_xml.to_xml
|
41
|
-
end
|
42
|
-
|
43
|
-
# Generates Dublin Core from the MODS in the descMetadata datastream using the LoC mods2dc stylesheet
|
44
|
-
# Should not be used for the Fedora DC datastream
|
45
|
-
# @raise [CrosswalkError] Raises an Exception if the generated DC is empty or has no children
|
46
|
-
# @return [Nokogiri::XML::Document] the DublinCore XML document object
|
47
|
-
def generate_dublin_core(include_collection_as_related_item: true)
|
48
|
-
DublinCoreService.new(self, include_collection_as_related_item: include_collection_as_related_item).ng_xml
|
49
|
-
end
|
50
|
-
deprecation_deprecate generate_dublin_core: 'Use DublinCoreService#ng_xml instead'
|
51
|
-
|
52
|
-
# @return [String] Public descriptive medatada XML
|
53
|
-
def generate_public_desc_md(**options)
|
54
|
-
PublicDescMetadataService.new(self).to_xml(**options)
|
55
|
-
end
|
56
|
-
deprecation_deprecate generate_public_desc_md: 'Use PublicDescMetadataService#to_xml instead'
|
57
|
-
|
58
|
-
# @param [Boolean] force Overwrite existing XML
|
59
|
-
# @return [String] descMetadata.content XML
|
60
|
-
def set_desc_metadata_using_label(force = false)
|
61
|
-
raise 'Cannot proceed, there is already content in the descriptive metadata datastream: ' + descMetadata.content.to_s unless force || descMetadata.new?
|
62
|
-
|
63
|
-
label = self.label
|
64
|
-
builder = Nokogiri::XML::Builder.new do |xml|
|
65
|
-
xml.mods(Dor::DescMetadataDS::MODS_HEADER_CONFIG) do
|
66
|
-
xml.titleInfo do
|
67
|
-
xml.title label
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
descMetadata.content = builder.to_xml
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.get_collection_title(obj)
|
75
|
-
obj.full_title
|
76
|
-
end
|
77
|
-
|
78
|
-
def full_title
|
79
|
-
stanford_mods.sw_title_display
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dor
|
4
|
-
module Eventable
|
5
|
-
extend Deprecation
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
self.deprecation_horizon = 'dor-services version 7.0.0'
|
8
|
-
|
9
|
-
included do
|
10
|
-
has_metadata name: 'events', type: Dor::EventsDS, label: 'Events'
|
11
|
-
end
|
12
|
-
|
13
|
-
def add_event(*args)
|
14
|
-
datastreams['events'].add_event *args
|
15
|
-
end
|
16
|
-
deprecation_deprecate add_event: 'call item.events.add_event instead.'
|
17
|
-
end
|
18
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dor
|
4
|
-
module Geoable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
has_metadata name: 'geoMetadata',
|
9
|
-
type: Dor::GeoMetadataDS,
|
10
|
-
label: 'Geographic Information Metadata in ISO 19139',
|
11
|
-
control_group: 'M'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dor
|
4
|
-
module Governable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
belongs_to :admin_policy_object, property: :is_governed_by, class_name: 'Dor::AdminPolicyObject'
|
9
|
-
has_and_belongs_to_many :collections, property: :is_member_of_collection, class_name: 'Dor::Collection'
|
10
|
-
has_and_belongs_to_many :sets, property: :is_member_of, class_name: 'Dor::Collection'
|
11
|
-
end
|
12
|
-
|
13
|
-
def initiate_apo_workflow(name)
|
14
|
-
CreateWorkflowService.create_workflow(self, name: name, create_ds: !new_record?)
|
15
|
-
end
|
16
|
-
deprecation_deprecate initiate_apo_workflow: 'Use Dor::Services::Client.object(object_identifier).workflow.create(wf_name:) instead'
|
17
|
-
|
18
|
-
def reset_to_apo_default
|
19
|
-
rightsMetadata.content = admin_policy_object.rightsMetadata.ng_xml
|
20
|
-
end
|
21
|
-
|
22
|
-
def set_read_rights(rights)
|
23
|
-
rightsMetadata.set_read_rights(rights)
|
24
|
-
unshelve_and_unpublish if rights == 'dark'
|
25
|
-
end
|
26
|
-
|
27
|
-
def unshelve_and_unpublish
|
28
|
-
if respond_to? :contentMetadata
|
29
|
-
content_ds = datastreams['contentMetadata']
|
30
|
-
unless content_ds.nil?
|
31
|
-
content_ds.ng_xml.xpath('/contentMetadata/resource//file').each_with_index do |file_node, index|
|
32
|
-
content_ds.ng_xml_will_change! if index == 0
|
33
|
-
file_node['publish'] = 'no'
|
34
|
-
file_node['shelve'] = 'no'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def add_collection(collection_or_druid)
|
41
|
-
collection =
|
42
|
-
case collection_or_druid
|
43
|
-
when String
|
44
|
-
Dor::Collection.find(collection_or_druid)
|
45
|
-
when Dor::Collection
|
46
|
-
collection_or_druid
|
47
|
-
end
|
48
|
-
collections << collection
|
49
|
-
sets << collection
|
50
|
-
end
|
51
|
-
|
52
|
-
def remove_collection(collection_or_druid)
|
53
|
-
collection =
|
54
|
-
case collection_or_druid
|
55
|
-
when String
|
56
|
-
Dor::Collection.find(collection_or_druid)
|
57
|
-
when Dor::Collection
|
58
|
-
collection_or_druid
|
59
|
-
end
|
60
|
-
|
61
|
-
collections.delete(collection)
|
62
|
-
sets.delete(collection)
|
63
|
-
end
|
64
|
-
|
65
|
-
# set the rights metadata datastream to the content of the APO's default object rights
|
66
|
-
def reapplyAdminPolicyObjectDefaults
|
67
|
-
rightsMetadata.content = admin_policy_object.datastreams['defaultObjectRights'].content
|
68
|
-
end
|
69
|
-
|
70
|
-
def rights
|
71
|
-
return nil unless respond_to? :rightsMetadata
|
72
|
-
return nil if rightsMetadata.nil?
|
73
|
-
|
74
|
-
xml = rightsMetadata.ng_xml
|
75
|
-
return nil if xml.search('//rightsMetadata').length != 1 # ORLY?
|
76
|
-
|
77
|
-
if xml.search('//rightsMetadata/access[@type=\'read\']/machine/group').length == 1
|
78
|
-
'Stanford'
|
79
|
-
elsif xml.search('//rightsMetadata/access[@type=\'read\']/machine/world').length == 1
|
80
|
-
'World'
|
81
|
-
elsif xml.search('//rightsMetadata/access[@type=\'discover\']/machine/none').length == 1
|
82
|
-
'Dark'
|
83
|
-
else
|
84
|
-
'None'
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
delegate :can_manage_item?, :can_manage_desc_metadata?, :can_manage_system_metadata?,
|
89
|
-
:can_manage_content?, :can_manage_rights?, :can_manage_embargo?,
|
90
|
-
:can_view_content?, :can_view_metadata?, to: Dor::Ability
|
91
|
-
|
92
|
-
deprecation_deprecate can_manage_item?: 'Use Dor::Ability.can_manage_item? instead'
|
93
|
-
deprecation_deprecate can_manage_desc_metadata?: 'Use Dor::Ability.can_manage_desc_metadata? instead'
|
94
|
-
deprecation_deprecate can_manage_system_metadata?: 'Use Dor::Ability.can_manage_system_metadata? instead'
|
95
|
-
deprecation_deprecate can_manage_content?: 'Use Dor::Ability.can_manage_content? instead'
|
96
|
-
deprecation_deprecate can_manage_rights?: 'Use Dor::Ability.can_manage_rights? instead'
|
97
|
-
deprecation_deprecate can_manage_embargo?: 'Use Dor::Ability.can_manage_embargo? instead'
|
98
|
-
deprecation_deprecate can_view_content?: 'Use Dor::Ability.can_view_content? instead'
|
99
|
-
deprecation_deprecate can_view_metadata?: 'Use Dor::Ability.can_view_metadata? instead'
|
100
|
-
end
|
101
|
-
end
|
@@ -1,172 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dor
|
4
|
-
module Identifiable
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
# ids for previous and current catkeys
|
8
|
-
CATKEY_TYPE_ID = 'catkey'
|
9
|
-
PREVIOUS_CATKEY_TYPE_ID = 'previous_catkey'
|
10
|
-
|
11
|
-
included do
|
12
|
-
has_metadata name: 'DC', type: SimpleDublinCoreDs, label: 'Dublin Core Record for self object'
|
13
|
-
has_metadata name: 'identityMetadata', type: Dor::IdentityMetadataDS, label: 'Identity Metadata'
|
14
|
-
end
|
15
|
-
|
16
|
-
module ClassMethods
|
17
|
-
attr_reader :object_type
|
18
|
-
def has_object_type(str)
|
19
|
-
@object_type = str
|
20
|
-
Dor.registered_classes[str] = self
|
21
|
-
end
|
22
|
-
|
23
|
-
# Overrides the method in ActiveFedora to mint a pid using SURI rather
|
24
|
-
# than the default Fedora sequence
|
25
|
-
def assign_pid(_obj)
|
26
|
-
return Dor::SuriService.mint_id if Dor::Config.suri.mint_ids
|
27
|
-
|
28
|
-
super
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
# helper method to get the tags as an array
|
33
|
-
def tags
|
34
|
-
identityMetadata.tag
|
35
|
-
end
|
36
|
-
|
37
|
-
# helper method to get just the content type tag
|
38
|
-
def content_type_tag
|
39
|
-
content_tag = tags.select { |tag| tag.include?('Process : Content Type') }
|
40
|
-
content_tag.size == 1 ? content_tag[0].split(':').last.strip : ''
|
41
|
-
end
|
42
|
-
|
43
|
-
# Convenience method
|
44
|
-
def source_id
|
45
|
-
identityMetadata.sourceId
|
46
|
-
end
|
47
|
-
|
48
|
-
# Convenience method
|
49
|
-
# @param [String] source_id the new source identifier
|
50
|
-
# @return [String] same value, as per Ruby assignment convention
|
51
|
-
# @raise [ArgumentError] see IdentityMetadataDS for logic
|
52
|
-
def source_id=(source_id)
|
53
|
-
identityMetadata.sourceId = source_id
|
54
|
-
end
|
55
|
-
alias set_source_id source_id=
|
56
|
-
deprecate set_source_id: 'Use source_id= instead'
|
57
|
-
|
58
|
-
# Convenience method to get the current catkey
|
59
|
-
# @return [String] current catkey value (or nil if none found)
|
60
|
-
def catkey
|
61
|
-
identityMetadata.otherId(CATKEY_TYPE_ID).first
|
62
|
-
end
|
63
|
-
|
64
|
-
# Convenience method to set the catkey
|
65
|
-
# @param [String] val the new source identifier
|
66
|
-
# @return [String] same value, as per Ruby assignment convention
|
67
|
-
def catkey=(val)
|
68
|
-
# if there was already a catkey in the record, store that in the "previous" spot (assuming there is no change)
|
69
|
-
identityMetadata.add_otherId("#{PREVIOUS_CATKEY_TYPE_ID}:#{catkey}") if val != catkey && !catkey.blank?
|
70
|
-
|
71
|
-
if val.blank? # if we are setting the catkey to blank, remove the node from XML
|
72
|
-
remove_other_Id(CATKEY_TYPE_ID)
|
73
|
-
elsif catkey.blank? # if there is no current catkey, then add it
|
74
|
-
add_other_Id(CATKEY_TYPE_ID, val)
|
75
|
-
else # if there is a current catkey, update the current catkey to the new value
|
76
|
-
update_other_Id(CATKEY_TYPE_ID, val)
|
77
|
-
end
|
78
|
-
|
79
|
-
val
|
80
|
-
end
|
81
|
-
|
82
|
-
# Convenience method to get the previous catkeys (will be an array)
|
83
|
-
# @return [Array] previous catkey values (empty array if none found)
|
84
|
-
def previous_catkeys
|
85
|
-
identityMetadata.otherId(PREVIOUS_CATKEY_TYPE_ID)
|
86
|
-
end
|
87
|
-
|
88
|
-
def add_other_Id(type, val)
|
89
|
-
raise 'There is an existing entry for ' + type + ', consider using update_other_Id().' if identityMetadata.otherId(type).length > 0
|
90
|
-
|
91
|
-
identityMetadata.add_otherId(type + ':' + val)
|
92
|
-
end
|
93
|
-
|
94
|
-
def update_other_Id(type, new_val, val = nil)
|
95
|
-
identityMetadata.ng_xml.search('//otherId[@name=\'' + type + '\']')
|
96
|
-
.select { |node| val.nil? || node.content == val }
|
97
|
-
.each { identityMetadata.ng_xml_will_change! }
|
98
|
-
.each { |node| node.content = new_val }
|
99
|
-
.any?
|
100
|
-
end
|
101
|
-
|
102
|
-
def remove_other_Id(type, val = nil)
|
103
|
-
identityMetadata.ng_xml.search('//otherId[@name=\'' + type + '\']')
|
104
|
-
.select { |node| val.nil? || node.content == val }
|
105
|
-
.each { identityMetadata.ng_xml_will_change! }
|
106
|
-
.each(&:remove)
|
107
|
-
.any?
|
108
|
-
end
|
109
|
-
|
110
|
-
# Add an administrative tag to an item, you will need to seperately save the item to write it to fedora
|
111
|
-
# @param tag [string] The tag you wish to add
|
112
|
-
def add_tag(tag)
|
113
|
-
TagService.add(self, tag)
|
114
|
-
end
|
115
|
-
deprecation_deprecate add_tag: 'Call TagService.add instead'
|
116
|
-
|
117
|
-
def remove_tag(tag)
|
118
|
-
TagService.remove(self, tag)
|
119
|
-
end
|
120
|
-
deprecation_deprecate remove_tag: 'Call TagService.remove instead'
|
121
|
-
|
122
|
-
def update_tag(old_tag, new_tag)
|
123
|
-
TagService.update(self, old_tag, new_tag)
|
124
|
-
end
|
125
|
-
deprecation_deprecate update_tag: 'Call TagService.update instead'
|
126
|
-
|
127
|
-
# a regex that can be used to identify the last part of a druid (e.g. oo000oo0001)
|
128
|
-
# @return [Regex] a regular expression to identify the ID part of the druid
|
129
|
-
def pid_regex
|
130
|
-
/[a-zA-Z]{2}[0-9]{3}[a-zA-Z]{2}[0-9]{4}/
|
131
|
-
end
|
132
|
-
|
133
|
-
# a regex that can be used to identify a full druid with prefix (e.g. druid:oo000oo0001)
|
134
|
-
# @return [Regex] a regular expression to identify a full druid
|
135
|
-
def druid_regex
|
136
|
-
/druid:#{pid_regex}/
|
137
|
-
end
|
138
|
-
|
139
|
-
# Since purl does not use the druid: prefix but much of dor does, use this function to strip the druid: if needed
|
140
|
-
# @return [String] the druid sans the druid: or if there was no druid: prefix, the entire string you passed
|
141
|
-
def remove_druid_prefix(druid = id)
|
142
|
-
result = druid.match(/#{pid_regex}/)
|
143
|
-
result.nil? ? druid : result[0] # if no matches, return the string passed in, otherwise return the match
|
144
|
-
end
|
145
|
-
|
146
|
-
# Override ActiveFedora::Core#adapt_to_cmodel (used with associations, among other places) to
|
147
|
-
# preferentially use the objectType asserted in the identityMetadata.
|
148
|
-
def adapt_to_cmodel
|
149
|
-
object_type = identityMetadata.objectType.first
|
150
|
-
object_class = Dor.registered_classes[object_type]
|
151
|
-
|
152
|
-
if object_class
|
153
|
-
instance_of?(object_class) ? self : adapt_to(object_class)
|
154
|
-
else
|
155
|
-
if ActiveFedora::VERSION < '8'
|
156
|
-
result = super
|
157
|
-
if result.class == Dor::Abstract
|
158
|
-
adapt_to(Dor::Item)
|
159
|
-
else
|
160
|
-
result
|
161
|
-
end
|
162
|
-
else
|
163
|
-
begin
|
164
|
-
super
|
165
|
-
rescue ActiveFedora::ModelNotAsserted
|
166
|
-
adapt_to(Dor::Item)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|