dor-services 4.22.3 → 4.22.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +8 -8
  2. data/bin/dor-indexer +19 -20
  3. data/bin/dor-indexerd +2 -3
  4. data/config/certs/robots-dor-dev.crt +29 -0
  5. data/config/certs/robots-dor-dev.key +27 -0
  6. data/config/dev_console_env.rb +77 -0
  7. data/lib/dor-services.rb +3 -3
  8. data/lib/dor/config.rb +15 -15
  9. data/lib/dor/datastreams/administrative_metadata_ds.rb +5 -5
  10. data/lib/dor/datastreams/content_metadata_ds.rb +181 -225
  11. data/lib/dor/datastreams/datastream_spec_solrizer.rb +1 -1
  12. data/lib/dor/datastreams/default_object_rights_ds.rb +8 -10
  13. data/lib/dor/datastreams/desc_metadata_ds.rb +35 -34
  14. data/lib/dor/datastreams/embargo_metadata_ds.rb +7 -7
  15. data/lib/dor/datastreams/events_ds.rb +11 -11
  16. data/lib/dor/datastreams/geo_metadata_ds.rb +86 -86
  17. data/lib/dor/datastreams/identity_metadata_ds.rb +19 -19
  18. data/lib/dor/datastreams/role_metadata_ds.rb +3 -3
  19. data/lib/dor/datastreams/simple_dublin_core_ds.rb +13 -13
  20. data/lib/dor/datastreams/version_metadata_ds.rb +5 -5
  21. data/lib/dor/datastreams/workflow_definition_ds.rb +21 -21
  22. data/lib/dor/migrations/identifiable/assert_adminPolicy.rb +1 -1
  23. data/lib/dor/migrations/identifiable/fix_model_assertions.rb +1 -1
  24. data/lib/dor/migrations/identifiable/record_remediation.rb +2 -2
  25. data/lib/dor/migrations/identifiable/uriify_augmented_contentlocation_refs.rb +1 -1
  26. data/lib/dor/migrations/identifiable/uriify_contentlocation_refs.rb +1 -1
  27. data/lib/dor/migrations/processable/unify_workflows.rb +4 -4
  28. data/lib/dor/migrations/versionable/add_missing_version_md.rb +1 -1
  29. data/lib/dor/models/admin_policy_object.rb +1 -1
  30. data/lib/dor/models/assembleable.rb +5 -5
  31. data/lib/dor/models/contentable.rb +27 -27
  32. data/lib/dor/models/describable.rb +168 -179
  33. data/lib/dor/models/discoverable.rb +13 -13
  34. data/lib/dor/models/editable.rb +55 -55
  35. data/lib/dor/models/embargoable.rb +26 -26
  36. data/lib/dor/models/eventable.rb +3 -3
  37. data/lib/dor/models/geoable.rb +8 -8
  38. data/lib/dor/models/governable.rb +14 -14
  39. data/lib/dor/models/identifiable.rb +117 -143
  40. data/lib/dor/models/item.rb +2 -2
  41. data/lib/dor/models/itemizable.rb +9 -9
  42. data/lib/dor/models/presentable.rb +8 -8
  43. data/lib/dor/models/preservable.rb +4 -4
  44. data/lib/dor/models/processable.rb +22 -23
  45. data/lib/dor/models/releaseable.rb +26 -26
  46. data/lib/dor/models/shelvable.rb +14 -14
  47. data/lib/dor/models/upgradable.rb +13 -13
  48. data/lib/dor/models/versionable.rb +2 -2
  49. data/lib/dor/models/workflow_object.rb +4 -4
  50. data/lib/dor/services/cleanup_reset_service.rb +27 -27
  51. data/lib/dor/services/cleanup_service.rb +4 -7
  52. data/lib/dor/services/digital_stacks_service.rb +10 -10
  53. data/lib/dor/services/merge_service.rb +1 -1
  54. data/lib/dor/services/metadata_handlers/mdtoolkit_handler.rb +2 -2
  55. data/lib/dor/services/metadata_service.rb +20 -20
  56. data/lib/dor/services/registration_service.rb +27 -27
  57. data/lib/dor/services/reset_workspace_service.rb +15 -15
  58. data/lib/dor/services/sdr_ingest_service.rb +6 -6
  59. data/lib/dor/services/search_service.rb +2 -2
  60. data/lib/dor/services/suri_service.rb +5 -5
  61. data/lib/dor/services/technical_metadata_service.rb +2 -3
  62. data/lib/dor/utils/ng_tidy.rb +9 -9
  63. data/lib/dor/utils/predicate_patch.rb +1 -1
  64. data/lib/dor/utils/solr_doc_helper.rb +2 -2
  65. data/lib/dor/version.rb +1 -1
  66. data/lib/dor/workflow/document.rb +19 -19
  67. data/lib/dor/workflow/graph.rb +36 -36
  68. data/lib/dor/workflow/process.rb +12 -12
  69. data/lib/tasks/dor.rake +1 -1
  70. data/lib/tasks/rdoc.rake +3 -3
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NhMWM3
14
+ OTQ0NzYwOGIwYTA0NDRlMWVjM2JkODhmNzdiZGYyMDc3ZTA3ZGMxZjc5OTFl
15
+ YjVmYzIyMjI0MDU4MDliNDQ4ODk0YjAxNjU1OTY5ZDZkN2I3Mzk=
data/bin/dor-indexer CHANGED
@@ -27,11 +27,11 @@ optparse = OptionParser.new do|opts|
27
27
  opts.on('-c', '--client-id ID', 'Stomp client ID') do |client_id|
28
28
  Dor::Config.stomp.client_id = client_id
29
29
  end
30
-
30
+
31
31
  opts.on('-v', 'Verbose') do
32
32
  options[:log_level] -= 1 if options[:log_level] > 0
33
33
  end
34
-
34
+
35
35
  opts.on('-h', '--help', 'Display this screen') do
36
36
  puts opts
37
37
  exit
@@ -53,16 +53,16 @@ begin
53
53
  @clientid = options[:client_id]
54
54
  @destination = options[:destination]
55
55
 
56
-
56
+
57
57
  @conn = Dor::Config.stomp.connection
58
58
  $stderr.print Time.now.to_s + " Getting output from #{@destination}\n"
59
-
59
+
60
60
  @conn.subscribe(@destination, {"activemq.subscriptionName" => @clientid, :ack =>"client" })
61
61
  while true
62
-
62
+
63
63
  begin
64
- Timeout::timeout(300) do
65
- @msg = @conn.receive
64
+ Timeout::timeout(300) do
65
+ @msg = @conn.receive
66
66
  end
67
67
  if @msg.nil?
68
68
  $stderr.print 'nil message\n'
@@ -85,18 +85,18 @@ begin
85
85
  @conn.ack @msg.headers["message-id"]
86
86
  end
87
87
  rescue Timeout::Error
88
- begin
89
- $stderr.print Time.now.to_s +" Sending heartbeat\n"
90
- @conn.begin('heartbeat')
91
- @conn.commit('heartbeat')
92
- rescue Exception => e
93
- body = "Unable to send heartbeat to broker\n"
94
- body << "\n\nExeption:\n" << he.inspect << "\n" << he.backtrace.join("\n")
95
- $stderr.print(Time.now.to_s + " Unable to send heartbeat")
96
- $stderr.print(body)
97
- end
98
-
99
-
88
+ begin
89
+ $stderr.print Time.now.to_s +" Sending heartbeat\n"
90
+ @conn.begin('heartbeat')
91
+ @conn.commit('heartbeat')
92
+ rescue Exception => e
93
+ body = "Unable to send heartbeat to broker\n"
94
+ body << "\n\nExeption:\n" << he.inspect << "\n" << he.backtrace.join("\n")
95
+ $stderr.print(Time.now.to_s + " Unable to send heartbeat")
96
+ $stderr.print(body)
97
+ end
98
+
99
+
100
100
  rescue Exception => e
101
101
  $stderr.print Time.now.to_s + " failed to update solr index for #{pid}: #<#{e.class.name}: #{e.message}>"
102
102
  end
@@ -105,4 +105,3 @@ begin
105
105
  rescue Exception => e
106
106
  p e
107
107
  end
108
-
data/bin/dor-indexerd CHANGED
@@ -43,12 +43,12 @@ log_dir=nil
43
43
  if ARGV[3]=='--log_dir'
44
44
  log_dir=ARGV[4]
45
45
  else
46
- puts "Log dir not specified"
46
+ puts "Log dir not specified"
47
47
  end
48
48
 
49
49
 
50
50
  if log_dir.empty?
51
- File.join(Dir.pwd,'log')
51
+ File.join(Dir.pwd,'log')
52
52
  end
53
53
 
54
54
 
@@ -70,4 +70,3 @@ version = '>=0'
70
70
  #app = Gem.bin_path('dor-services','dor-indexer',version)
71
71
  app = File.expand_path('../dor-indexer',__FILE__)
72
72
  Daemons.run(app,options)
73
-
@@ -0,0 +1,29 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIE9zCCAt8CCQCcUJVDTu7rTjANBgkqhkiG9w0BAQUFADCBvzELMAkGA1UEBhMC
3
+ VVMxEzARBgNVBAgTCkNhbGlmb3JuaWExETAPBgNVBAcTCFN0YW5mb3JkMRwwGgYD
4
+ VQQKExNTdGFuZm9yZCBVbml2ZXJzaXR5MRIwEAYDVQQLEwlMaWJyYXJpZXMxJTAj
5
+ BgNVBAMTHFNVTCBET1IgKGRldi90ZXN0KSBhY2Nlc3MgQ0ExLzAtBgkqhkiG9w0B
6
+ CQEWIHN1bC13ZWJtYXN0ZXJAbGlzdHMuc3RhbmZvcmQuZWR1MB4XDTEyMDkyNjE1
7
+ NTQzNVoXDTIyMDkyNDE1NTQzNVowgboxCzAJBgNVBAYTAlVTMRMwEQYD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YuYFu7txtwC2mZXc=
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,77 @@
1
+ cert_dir = File.join(File.dirname(__FILE__), 'certs')
2
+
3
+ Dor::Config.configure do
4
+
5
+ ssl do
6
+ cert_file File.join(cert_dir, 'robots-dor-dev.crt')
7
+ key_file File.join(cert_dir, 'robots-dor-dev.key')
8
+ key_pass ''
9
+ end
10
+
11
+ suri do
12
+ mint_ids true
13
+ id_namespace 'druid'
14
+ url 'https://lyberservices-dev.stanford.edu'
15
+ user 'labware'
16
+ pass 'lyberteam'
17
+ end
18
+
19
+ metadata do
20
+ exist.url 'http://viewer:l3l%40nd@lyberapps-dev.stanford.edu/exist/rest/'
21
+ catalog.url 'http://lyberservices-prod.stanford.edu/catalog/mods'
22
+ end
23
+
24
+ stacks do
25
+ document_cache_host 'purl-dev.stanford.edu'
26
+ local_stacks_root '/stacks'
27
+ local_document_cache_root '/purl/document_cache'
28
+ local_workspace_root '/dor/workspace'
29
+ end
30
+
31
+ solrizer.url 'http://sul-solr.stanford.edu/solr/argo_test'
32
+ fedora.url 'https://sul-dor-test.stanford.edu/fedora'
33
+ workflow.url 'https://lyberservices-dev.stanford.edu/workflow/'
34
+ dor_services.url 'https://dorAdmin:dorAdmin@sul-lyberservices-dev.stanford.edu/dor'
35
+
36
+ cleanup do
37
+ local_workspace_root '/dor/workspace'
38
+ local_export_home '/dor/export'
39
+ end
40
+
41
+ sdr do
42
+ url 'https://sdrAdmin:sdrAdmin@sdr-services-test.stanford.edu/sdr/'
43
+ local_workspace_root '/dor/workspace'
44
+ local_export_home '/dor/export'
45
+ datastreams do
46
+ administrativeMetadata 'optional'
47
+ contentMetadata 'optional'
48
+ descMetadata 'required'
49
+ defaultObjectRights 'optional'
50
+ events 'optional'
51
+ embargoMetadata 'optional'
52
+ identityMetadata 'required'
53
+ provenanceMetadata 'required'
54
+ relationshipMetadata 'required'
55
+ rightsMetadata 'optional'
56
+ roleMetadata 'optional'
57
+ sourceMetadata 'optional'
58
+ technicalMetadata 'optional'
59
+ versionMetadata 'required'
60
+ workflows 'optional'
61
+ end
62
+ end
63
+
64
+ accessioning_robot_sleep_time 30
65
+
66
+ end
67
+
68
+ #WORKFLOW_URI = 'http://lyberservices-test.stanford.edu/workflow'
69
+
70
+ # Constants for Dor::WorkflowService
71
+ #module Dor
72
+ # CREATE_WORKFLOW = DOR_CREATE_WORKFLOW = true
73
+ # WF_URI = 'http://lyberservices-test.stanford.edu/workflow'
74
+ #end
75
+
76
+ # External application locations
77
+ JHOVE_HOME = File.join(ENV['HOME'], 'jhoveToolkit')
data/lib/dor-services.rb CHANGED
@@ -30,11 +30,11 @@ module Dor
30
30
  # Dor.load_instance() if the item is not in the index, or is improperly
31
31
  # indexed.
32
32
  # @param [String] pid The object's PID
33
- def find pid, opts={}
34
- self.find_all(%{id:"#{pid}"}, opts).first || self.load_instance(pid)
33
+ def find pid, opts = {}
34
+ find_all(%{id:"#{pid}"}, opts).first || load_instance(pid)
35
35
  end
36
36
 
37
- def find_all query, opts={}
37
+ def find_all query, opts = {}
38
38
  ensure_models_loaded!
39
39
  af_version = Gem::Version.new(ActiveFedora::VERSION)
40
40
  if opts[:lightweight] and af_version < Gem::Version.new('4.0.0.rc9')
data/lib/dor/config.rb CHANGED
@@ -29,27 +29,27 @@ module Dor
29
29
  params[:timeout] = result.workflow.timeout if result.workflow.timeout
30
30
  # params[:logger] = Logger.new('logs/workflow_service.log', 'weekly') # if you want to control the logger, insert it here.
31
31
  Dor::WorkflowService.configure result.workflow.url, params
32
- return result
32
+ result
33
33
  end
34
34
 
35
- def autoconfigure(url, cert_file=Config.ssl.cert_file, key_file=Config.ssl.key_file, key_pass=Config.ssl.key_pass)
35
+ def autoconfigure(url, cert_file = Config.ssl.cert_file, key_file = Config.ssl.key_file, key_pass = Config.ssl.key_pass)
36
36
  client = make_rest_client(url, cert_file, key_file, key_pass)
37
37
  config = Confstruct::Configuration.symbolize_hash JSON.parse(client.get :accept => 'application/json')
38
- self.configure(config)
38
+ configure(config)
39
39
  end
40
40
 
41
41
  def sanitize
42
- self.dup
42
+ dup
43
43
  end
44
44
 
45
- def make_rest_client(url, cert=Config.ssl.cert_file, key=Config.ssl.key_file, pass=Config.ssl.key_pass)
45
+ def make_rest_client(url, cert = Config.ssl.cert_file, key = Config.ssl.key_file, pass = Config.ssl.key_pass)
46
46
  params = {}
47
47
  params[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(cert)) if cert
48
48
  params[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(key), pass) if key
49
49
  RestClient::Resource.new(url, params)
50
50
  end
51
51
 
52
- def make_solr_connection(add_opts={})
52
+ def make_solr_connection(add_opts = {})
53
53
  opts = Config.solrizer.opts.merge(add_opts).merge(
54
54
  :url => Config.solrizer.url
55
55
  )
@@ -71,7 +71,7 @@ module Dor
71
71
  }
72
72
  },
73
73
  :sdr => {
74
- :rest_client => Confstruct.deferred { |c| config.make_rest_client c.url },
74
+ :rest_client => Confstruct.deferred { |c| config.make_rest_client c.url }
75
75
  },
76
76
  :gsearch => {
77
77
  :rest_client => Confstruct.deferred { |c| config.make_rest_client c.rest_url },
@@ -101,11 +101,11 @@ module Dor
101
101
  if ActiveFedora.respond_to?(:configurator)
102
102
  if config.solrizer.url.present?
103
103
  ActiveFedora::SolrService.register
104
- ActiveFedora::SolrService.instance.instance_variable_set :@conn, self.make_solr_connection
104
+ ActiveFedora::SolrService.instance.instance_variable_set :@conn, make_solr_connection
105
105
  end
106
106
  else
107
- ActiveFedora::RubydoraConnection.connect self.fedora_config if self.fedora.url.present?
108
- if self.solrizer.url.present?
107
+ ActiveFedora::RubydoraConnection.connect fedora_config if fedora.url.present?
108
+ if solrizer.url.present?
109
109
  ActiveFedora::SolrService.register config.solrizer.url, config.solrizer.opts
110
110
  conn = ActiveFedora::SolrService.instance.conn.connection
111
111
  if config.ssl.cert_file.present?
@@ -125,15 +125,15 @@ module Dor
125
125
  def init *args; end
126
126
 
127
127
  def fedora_config
128
- fedora_uri = URI.parse(self.fedora.url)
129
- connection_opts = { :url => self.fedora.safeurl, :user => fedora_uri.user, :password => fedora_uri.password }
130
- connection_opts[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(self.ssl.cert_file)) if self.ssl.cert_file.present?
131
- connection_opts[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(self.ssl.key_file),self.ssl.key_pass) if self.ssl.key_file.present?
128
+ fedora_uri = URI.parse(fedora.url)
129
+ connection_opts = { :url => fedora.safeurl, :user => fedora_uri.user, :password => fedora_uri.password }
130
+ connection_opts[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(ssl.cert_file)) if ssl.cert_file.present?
131
+ connection_opts[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(ssl.key_file),ssl.key_pass) if ssl.key_file.present?
132
132
  connection_opts
133
133
  end
134
134
 
135
135
  def solr_config
136
- { :url => self.solrizer.url }
136
+ { :url => solrizer.url }
137
137
  end
138
138
 
139
139
  def predicate_config
@@ -99,21 +99,21 @@ class AdministrativeMetadataDS < ActiveFedora::OmDatastream
99
99
  #################################################################################
100
100
 
101
101
  def default_workflow_lane= lane
102
- self.defaults.initiate_workflow.lane = lane
102
+ defaults.initiate_workflow.lane = lane
103
103
  end
104
104
 
105
105
  def default_workflow_lane
106
- self.defaults.initiate_workflow.lane.first
106
+ defaults.initiate_workflow.lane.first
107
107
  end
108
108
 
109
109
  def default_shelving_path= path
110
- self.defaults.shelving.path = path
110
+ defaults.shelving.path = path
111
111
  end
112
112
 
113
113
  def default_shelving_path
114
- self.defaults.shelving.path.first
114
+ defaults.shelving.path.first
115
115
  end
116
116
 
117
117
  end
118
118
 
119
- end
119
+ end
@@ -1,29 +1,29 @@
1
1
  module Dor
2
- class ContentMetadataDS < ActiveFedora::OmDatastream
2
+ class ContentMetadataDS < ActiveFedora::OmDatastream
3
3
  include Upgradable
4
4
  include SolrDocHelper
5
5
 
6
6
  set_terminology do |t|
7
- t.root :path => 'contentMetadata', :index_as => [:not_searchable]
8
- t.contentType :path => '/contentMetadata/@type', :index_as => [:not_searchable]
9
- t.stacks :path=> '/contentMetadata/@stacks', :index_as => [:not_searchable]
7
+ t.root :path => 'contentMetadata', :index_as => [:not_searchable]
8
+ t.contentType :path => '/contentMetadata/@type', :index_as => [:not_searchable]
9
+ t.stacks :path => '/contentMetadata/@stacks', :index_as => [:not_searchable]
10
10
  t.resource(:index_as => [:not_searchable]) do
11
- t.id_ :path => { :attribute => 'id' }
12
- t.sequence :path => { :attribute => 'sequence' }#, :data_type => :integer
13
- t.type_ :path => { :attribute => 'type' }, :index_as => [:displayable]
11
+ t.id_ :path => { :attribute => 'id' }
12
+ t.sequence :path => { :attribute => 'sequence' } #, :data_type => :integer
13
+ t.type_ :path => { :attribute => 'type' }, :index_as => [:displayable]
14
14
  t.attribute(:path => 'attr', :index_as => [:not_searchable]) do
15
- t.name :path => { :attribute => 'name' }, :index_as => [:not_searchable]
15
+ t.name :path => { :attribute => 'name' }, :index_as => [:not_searchable]
16
16
  end
17
17
  t.file(:index_as => [:not_searchable]) do
18
- t.id_ :path => { :attribute => 'id' }
18
+ t.id_ :path => { :attribute => 'id' }
19
19
  t.mimeType :path => { :attribute => 'mimeType' }, :index_as => [:displayable]
20
20
  t.dataType :path => { :attribute => 'dataType' }, :index_as => [:displayable]
21
- t.size :path => { :attribute => 'size' }, :index_as => [:displayable]#, :data_type => :long
22
- t.shelve :path => { :attribute => 'shelve' }, :index_as => [:not_searchable]#, :data_type => :boolean
23
- t.publish :path => { :attribute => 'publish' }, :index_as => [:not_searchable]#, :data_type => :boolean
24
- t.preserve :path => { :attribute => 'preserve' }, :index_as => [:not_searchable]#, :data_type => :boolean
21
+ t.size :path => { :attribute => 'size' }, :index_as => [:displayable] #, :data_type => :long
22
+ t.shelve :path => { :attribute => 'shelve' }, :index_as => [:not_searchable] #, :data_type => :boolean
23
+ t.publish :path => { :attribute => 'publish' }, :index_as => [:not_searchable] #, :data_type => :boolean
24
+ t.preserve :path => { :attribute => 'preserve' }, :index_as => [:not_searchable] #, :data_type => :boolean
25
25
  t.checksum do
26
- t.type_ :path => { :attribute => 'type' }
26
+ t.type_ :path => { :attribute => 'type' }
27
27
  end
28
28
  end
29
29
  t.shelved_file(:path => 'file', :attributes => {:shelve=>'yes'}, :index_as => [:not_searchable]) do
@@ -34,305 +34,261 @@ module Dor
34
34
  end
35
35
 
36
36
  def public_xml
37
- result = self.ng_xml.clone
38
- result.xpath('/contentMetadata/resource[not(file[(@deliver="yes" or @publish="yes")])]').each { |n| n.remove }
39
- result.xpath('/contentMetadata/resource/file[not(@deliver="yes" or @publish="yes")]').each { |n| n.remove }
37
+ result = ng_xml.clone
38
+ result.xpath('/contentMetadata/resource[not(file[(@deliver="yes" or @publish="yes")])]' ).each { |n| n.remove }
39
+ result.xpath('/contentMetadata/resource/file[not(@deliver="yes" or @publish="yes")]' ).each { |n| n.remove }
40
40
  result.xpath('/contentMetadata/resource/file').xpath('@preserve|@shelve|@publish|@deliver').each { |n| n.remove }
41
41
  result.xpath('/contentMetadata/resource/file/checksum').each { |n| n.remove }
42
42
  result
43
43
  end
44
+
44
45
  def add_file(file, resource_name)
45
- xml=self.ng_xml
46
+ xml = ng_xml
46
47
  resource_nodes = xml.search('//resource[@id=\''+resource_name+'\']')
47
- if resource_nodes.length==0
48
- raise 'resource doesnt exist.'
49
- end
50
- node=resource_nodes.first
51
- file_node=Nokogiri::XML::Node.new('file',xml)
52
- file_node['id']=file[:name]
53
- file_node['shelve']=file[:shelve] ? file[:shelve] : ''
54
- file_node['publish']=file[:publish] ? file[:publish] : ''
55
- file_node['preserve']=file[:preserve] ? file[:preserve] : ''
48
+ raise 'resource doesnt exist.' if resource_nodes.length == 0
49
+ node = resource_nodes.first
50
+ file_node = Nokogiri::XML::Node.new('file', xml)
51
+ file_node['id'] = file[:name]
52
+ file_node['shelve'] = file[:shelve ] ? file[:shelve ] : ''
53
+ file_node['publish'] = file[:publish ] ? file[:publish ] : ''
54
+ file_node['preserve'] = file[:preserve] ? file[:preserve] : ''
56
55
  node.add_child(file_node)
57
56
 
58
- if file[:md5]
59
- checksum_node=Nokogiri::XML::Node.new('checksum',xml)
60
- checksum_node['type']='md5'
61
- checksum_node.content=file[:md5]
57
+ [:md5, :sha1].each do |algo|
58
+ next unless file[algo]
59
+ checksum_node = Nokogiri::XML::Node.new('checksum', xml)
60
+ checksum_node['type'] = algo.to_s
61
+ checksum_node.content = file[algo]
62
62
  file_node.add_child(checksum_node)
63
63
  end
64
- if file[:sha1]
65
- checksum_node=Nokogiri::XML::Node.new('checksum',xml)
66
- checksum_node['type']='sha1'
67
- checksum_node.content=file[:sha1]
68
- file_node.add_child(checksum_node)
69
- end
70
- if file[:size]
71
- file_node['size']=file[:size]
72
- end
73
- if file[:mime_type]
74
- file_node['mimetype']=file[:mime_type]
75
- end
76
- self.content=xml.to_s
77
- self.save
64
+ file_node['size' ] = file[:size ] if file[:size]
65
+ file_node['mimetype'] = file[:mime_type] if file[:mime_type]
66
+ self.content = xml.to_s
67
+ save
78
68
  end
79
69
 
80
- def add_resource(files,resource_name, position,type="file")
81
- xml=self.ng_xml
82
- if xml.search('//resource[@id=\''+resource_name+'\']').length>0
83
- raise 'resource '+resource_name+' already exists'
84
- end
85
- node=nil
86
-
87
- max=-1
70
+ def add_resource(files,resource_name, position,type = "file")
71
+ xml = ng_xml
72
+ raise "resource #{resource_name} already exists" if xml.search('//resource[@id=\'' + resource_name + '\']').length > 0
73
+ max = -1
88
74
  xml.search('//resource').each do |node|
89
- if node['sequence'].to_i>max
90
- max=node['sequence'].to_i
91
- end
75
+ max = node['sequence'].to_i if node['sequence'].to_i > max
92
76
  end
93
77
  #renumber all of the resources that will come after the newly added one
94
- while max>position do
95
- node=xml.search('//resource[@sequence=\'' + position + '\']')
96
- if node.length>0
97
- node=node.first
98
- node[sequence]=max+1
78
+ while max > position do
79
+ node = xml.search('//resource[@sequence=\'' + position + '\']')
80
+ if node.length > 0
81
+ node = node.first
82
+ node[sequence] = max + 1
99
83
  end
100
- max=max-1
84
+ max -= 1
101
85
  end
102
- node=Nokogiri::XML::Node.new('resource',xml)
103
- node['sequence']=position.to_s
104
- node['id']=resource_name
105
- node['type']=type
86
+ node = Nokogiri::XML::Node.new('resource',xml)
87
+ node['sequence'] = position.to_s
88
+ node['id'] = resource_name
89
+ node['type'] = type
106
90
  files.each do |file|
107
- file_node=Nokogiri::XML::Node.new('file',xml)
108
- file_node['shelve']=file[:shelve] ? file[:shelve] : ''
109
- file_node['publish']=file[:publish] ? file[:publish] : ''
110
- file_node['preserve']=file[:preserve] ? file[:preserve] : ''
111
- file_node['id']=file[:name]
91
+ file_node = Nokogiri::XML::Node.new('file', xml)
92
+ file_node['shelve' ] = file[:shelve ] ? file[:shelve ] : ''
93
+ file_node['publish' ] = file[:publish ] ? file[:publish ] : ''
94
+ file_node['preserve'] = file[:preserve] ? file[:preserve] : ''
95
+ file_node['id' ] = file[:name]
112
96
  node.add_child(file_node)
113
-
114
- if not file[:md5].nil?
115
- checksum_node=Nokogiri::XML::Node.new('checksum',xml)
116
- checksum_node['type']='md5'
117
- checksum_node.content=file[:md5]
118
- file_node.add_child(checksum_node)
119
- end
120
- if not file[:sha1].nil?
121
- checksum_node=Nokogiri::XML::Node.new('checksum',xml)
122
- checksum_node['type']='sha1'
123
- checksum_node.content=file[:sha1]
97
+ [:md5, :sha1].each do |algo|
98
+ next unless file[algo]
99
+ checksum_node = Nokogiri::XML::Node.new('checksum', xml)
100
+ checksum_node['type'] = algo.to_s
101
+ checksum_node.content = file[algo]
124
102
  file_node.add_child(checksum_node)
125
103
  end
126
- if file[:size]
127
- file_node['size']=file[:size]
128
- end
129
- end
104
+ file_node['size'] = file[:size] if file[:size]
105
+ end
130
106
  xml.search('//contentMetadata').first.add_child(node)
131
- self.content=xml.to_s
132
- self.save
107
+ self.content = xml.to_s
108
+ save
133
109
  end
134
110
 
135
111
  def remove_resource resource_name
136
- xml=self.ng_xml
137
- position=-1
138
-
139
- resources=xml.search('//resource[@id=\''+resource_name+'\']')
140
- if resources.length!=1
141
- raise 'Resource is missing or duplicated!'
142
- end
143
- position=resources.first['sequence']
112
+ xml = ng_xml
113
+ position = -1
114
+ resources = xml.search('//resource[@id=\'' + resource_name + '\']')
115
+ raise 'Resource is missing or duplicated!' if resources.length != 1
116
+ position = resources.first['sequence']
144
117
  resources.first.remove
145
- position=position.to_i+1
118
+ position = position.to_i + 1
146
119
  while true
147
- res=xml.search('//resource[@sequence=\''+position.to_s+'\']')
148
- if(res.length==0)
149
- break
150
- end
151
- res['sequence']=position.to_s
152
- position=position+1
120
+ res = xml.search('//resource[@sequence=\'' + position.to_s + '\']')
121
+ break if res.length == 0
122
+ res['sequence'] = position.to_s
123
+ position += 1
153
124
  end
154
- self.content=xml.to_s
155
- self.save
125
+ self.content = xml.to_s
126
+ save
156
127
  end
157
128
 
158
129
  def remove_file file_name
159
- xml=self.ng_xml
160
- xml.search('//file[@id=\''+file_name+'\']').each do |node|
130
+ xml = ng_xml
131
+ xml.search('//file[@id=\'' + file_name + '\']').each do |node|
161
132
  node.remove
162
133
  end
163
- self.content=xml.to_s
164
- self.save
134
+ self.content = xml.to_s
135
+ save
165
136
  end
137
+
166
138
  def update_attributes file_name, publish, shelve, preserve
167
- xml=self.ng_xml
168
- file_node=xml.search('//file[@id=\''+file_name+'\']').first
169
- file_node['shelve']=shelve
170
- file_node['publish']=publish
171
- file_node['preserve']=preserve
172
- self.content=xml.to_s
173
- self.save
139
+ xml = ng_xml
140
+ file_node = xml.search('//file[@id=\'' + file_name + '\']').first
141
+ file_node['shelve' ] = shelve
142
+ file_node['publish' ] = publish
143
+ file_node['preserve'] = preserve
144
+ self.content = xml.to_s
145
+ save
174
146
  end
147
+
175
148
  def update_file file, old_file_id
176
- xml=self.ng_xml
177
- file_node=xml.search('//file[@id=\''+old_file_id+'\']').first
178
- file_node['id']=file[:name]
179
- if not file[:md5].nil?
180
- checksum_node=xml.search('//file[@id=\''+old_file_id+'\']/checksum[@type=\'md5\']').first
149
+ xml = ng_xml
150
+ file_node = xml.search('//file[@id=\'' + old_file_id + '\']').first
151
+ file_node['id'] = file[:name]
152
+ unless file[:md5].nil?
153
+ checksum_node = xml.search('//file[@id=\'' + old_file_id + '\']/checksum[@type=\'md5\']').first
181
154
  if checksum_node.nil?
182
- checksum_node=Nokogiri::XML::Node.new('checksum',xml)
155
+ checksum_node = Nokogiri::XML::Node.new('checksum', xml)
183
156
  file_node.add_child(checksum_node)
184
157
  end
185
- checksum_node['type']='md5'
186
- checksum_node.content=file[:md5]
158
+ checksum_node['type'] = 'md5'
159
+ checksum_node.content = file[:md5]
187
160
  end
188
- if not file[:sha1].nil?
189
- checksum_node=xml.search('//file[@id=\''+old_file_id+'\']/checksum[@type=\'sha1\']').first
161
+ unless file[:sha1].nil?
162
+ checksum_node = xml.search('//file[@id=\'' + old_file_id + '\']/checksum[@type=\'sha1\']').first
190
163
  if checksum_node.nil?
191
- checksum_node=Nokogiri::XML::Node.new('checksum',xml)
164
+ checksum_node = Nokogiri::XML::Node.new('checksum', xml)
192
165
  file_node.add_child(checksum_node)
193
166
  end
194
- checksum_node['type']='sha1'
195
- checksum_node.content=file[:sha1]
196
- end
197
- if file[:size]
198
- file_node['size']=file[:size]
199
- end
200
- if file[:shelve]
201
- file_node['shelve']=file[:shelve]
202
- end
203
- if file[:preserve]
204
- file_node['preserve']=file[:preserve]
167
+ checksum_node['type'] = 'sha1'
168
+ checksum_node.content = file[:sha1]
205
169
  end
206
- if file[:publish]
207
- file_node['publish']=file[:publish]
208
- end
209
- self.content=xml.to_s
210
- self.save
170
+
171
+ file_node['size' ] = file[:size ] if file[:size]
172
+ file_node['shelve' ] = file[:shelve ] if file[:shelve]
173
+ file_node['preserve'] = file[:preserve] if file[:preserve]
174
+ file_node['publish' ] = file[:publish ] if file[:publish]
175
+ self.content = xml.to_s
176
+ save
211
177
  end
178
+
212
179
  # Terminology-based solrization is going to be painfully slow for large
213
180
  # contentMetadata streams. Just select the relevant elements instead.
214
- def to_solr(solr_doc=Hash.new, *args)
215
- doc = self.ng_xml
181
+ def to_solr(solr_doc = {}, *args)
182
+ doc = ng_xml
216
183
  if doc.root['type']
217
- shelved_file_count=0
218
- content_file_count=0
219
- resource_type_counts={}
220
- resource_count=0
221
- preserved_size=0
222
- first_shelved_image=nil
184
+ shelved_file_count = 0
185
+ content_file_count = 0
186
+ resource_type_counts = {}
187
+ resource_count = 0
188
+ preserved_size = 0
189
+ first_shelved_image = nil
223
190
  add_solr_value(solr_doc, "content_type", doc.root['type'], :string, [:facetable])
224
- doc.xpath('contentMetadata/resource').sort { |a,b| a['sequence'].to_i <=> b['sequence'].to_i }.each do |resource|
225
- resource_count+=1
226
- if(resource['type'])
191
+ doc.xpath('contentMetadata/resource').sort { |a, b| a['sequence'].to_i <=> b['sequence'].to_i }.each do |resource|
192
+ resource_count += 1
193
+ if resource['type']
227
194
  if resource_type_counts[resource['type']]
228
- resource_type_counts[resource['type']]+=1
195
+ resource_type_counts[resource['type']] += 1
229
196
  else
230
- resource_type_counts[resource['type']]=1
197
+ resource_type_counts[resource['type']] = 1
231
198
  end
232
199
  end
233
200
  resource.xpath('file').each do |file|
234
- content_file_count+=1
201
+ content_file_count += 1
235
202
  if file['shelve'] == 'yes'
236
- shelved_file_count+=1
237
- if first_shelved_image.nil? and file['id'].match(/jp2$/)
238
- first_shelved_image=file['id']
239
- end
240
- end
241
- if file['preserve'] == 'yes'
242
- preserved_size += file['size'].to_i
203
+ shelved_file_count += 1
204
+ first_shelved_image = file['id'] if first_shelved_image.nil? && file['id'].match(/jp2$/)
243
205
  end
206
+ preserved_size += file['size'].to_i if file['preserve'] == 'yes'
244
207
  end
245
208
  end
246
- add_solr_value(solr_doc, "content_file_count", content_file_count.to_s, :string, [:searchable, :displayable])
247
- add_solr_value(solr_doc, "shelved_content_file_count", shelved_file_count.to_s, :string, [:searchable, :displayable])
248
- add_solr_value(solr_doc, "resource_count", resource_count.to_s, :string, [:searchable, :displayable])
249
- add_solr_value(solr_doc, "preserved_size", preserved_size.to_s, :string, [:searchable, :displayable])
209
+ add_solr_value(solr_doc, 'content_file_count', content_file_count.to_s, :string, [:searchable, :displayable])
210
+ add_solr_value(solr_doc, 'shelved_content_file_count', shelved_file_count.to_s, :string, [:searchable, :displayable])
211
+ add_solr_value(solr_doc, 'resource_count', resource_count.to_s, :string, [:searchable, :displayable])
212
+ add_solr_value(solr_doc, 'preserved_size', preserved_size.to_s, :string, [:searchable, :displayable])
250
213
  resource_type_counts.each do |key, count|
251
- add_solr_value(solr_doc, key+"_resource_count", count.to_s, :string, [:searchable, :displayable])
214
+ add_solr_value(solr_doc, key + '_resource_count', count.to_s, :string, [:searchable, :displayable])
252
215
  end
253
- if not first_shelved_image.nil?
254
- add_solr_value(solr_doc, "first_shelved_image", first_shelved_image, :string, [:displayable])
216
+ unless first_shelved_image.nil?
217
+ add_solr_value(solr_doc, 'first_shelved_image', first_shelved_image, :string, [:displayable])
255
218
  end
256
219
  end
257
220
  solr_doc
258
221
  end
222
+
259
223
  def rename_file old_name, new_name
260
- xml=self.ng_xml
261
- file_node=xml.search('//file[@id=\''+old_name+'\']').first
262
- file_node['id']=new_name
263
- self.content=xml.to_s
264
- self.save
224
+ xml = ng_xml
225
+ file_node = xml.search('//file[@id=\'' + old_name + '\']').first
226
+ file_node['id'] = new_name
227
+ self.content = xml.to_s
228
+ save
265
229
  end
266
230
 
267
231
  def update_resource_label resource_name, new_label
268
- xml=self.ng_xml
269
- resource_node=xml.search('//resource[@id=\''+resource_name+'\']')
270
- if(resource_node.length!=1)
271
- raise 'Resource not found or duplicate found.'
272
- end
273
- labels=xml.search('//resource[@id=\''+resource_name+'\']/label')
274
- if(labels.length==0)
232
+ xml = ng_xml
233
+ resource_node = xml.search('//resource[@id=\'' + resource_name + '\']')
234
+ raise 'Resource not found or duplicate found.' unless resource_node.length == 1
235
+ labels = xml.search('//resource[@id=\'' + resource_name + '\']/label')
236
+ if labels.length == 0
275
237
  #create a label
276
- label_node = Nokogiri::XML::Node.new('label',xml)
277
- label_node.content=new_label
238
+ label_node = Nokogiri::XML::Node.new('label', xml)
239
+ label_node.content = new_label
278
240
  resource_node.first.add_child(label_node)
279
241
  else
280
- labels.first.content=new_label
242
+ labels.first.content = new_label
281
243
  end
282
244
  end
245
+
283
246
  def update_resource_type resource, new_type
284
- xml=self.ng_xml
285
- resource_node=xml.search('//resource[@id=\''+resource_name+'\']')
286
- if(resource_node.length!=1)
287
- raise 'Resource not found or duplicate found.'
288
- end
289
- resource_node.first['type']=new_type
247
+ xml = ng_xml
248
+ resource_node = xml.search('//resource[@id=\'' + resource_name + '\']')
249
+ raise 'Resource not found or duplicate found.' unless resource_node.length == 1
250
+ resource_node.first['type'] = new_type
290
251
  end
291
252
 
292
253
  def move_resource resource_name, new_position
293
- xml=self.ng_xml
294
- file_node=xml.search('//resource[@id=\''+resource_name+'\']')
295
- if(file_node.length!=1)
296
- raise 'Resource not found or duplicate found.'
297
- end
298
- position=file_node.first['sequence'].to_i
299
- #is the resource being moved earlier in the sequence or later?
300
- new_position=new_position.to_i
301
- if new_position>position
302
- counter=position
254
+ xml = ng_xml
255
+ file_node = xml.search('//resource[@id=\''+resource_name+'\']')
256
+ raise 'Resource not found or duplicate found.' unless file_node.length == 1
257
+ position = file_node.first['sequence'].to_i
258
+ # is the resource being moved earlier in the sequence or later?
259
+ new_position = new_position.to_i
260
+ if new_position > position
261
+ counter = position
303
262
  while true
304
- if counter == position
305
- break
306
- end
307
- item=xml.search('/resource[@id=\''+counter.to_s+'\']').first
308
- counter=counter+1
309
- item['sequence']=counter.to_s
263
+ break if counter == position
264
+ item = xml.search('/resource[@id=\'' + counter.to_s + '\']').first
265
+ counter += 1
266
+ item['sequence'] = counter.to_s
310
267
  end
311
268
  else
312
- counter=position
269
+ counter = position
313
270
  while true
314
- if counter == new_position
315
- break
316
- end
317
- item=xml.search('/resource[@id=\''+counter.to_s+'\']').first
318
- counter=counter-1
319
- item['sequence']=counter.to_s
271
+ break if counter == new_position
272
+ item = xml.search('/resource[@id=\'' + counter.to_s + '\']').first
273
+ counter -= 1
274
+ item['sequence'] = counter.to_s
320
275
  end
321
276
  end
322
277
  end
323
- #Set the content type to and the resource types for all resources
324
- #@param new_type [String] the new content type, ex book
325
- #@param new_resource_type [String] the new type for all resources, ex book
278
+
279
+ # Set the content type to and the resource types for all resources
280
+ # @param new_type [String] the new content type, ex book
281
+ # @param new_resource_type [String] the new type for all resources, ex book
326
282
  def set_content_type old_type, old_resource_type, new_type, new_resource_type
327
- xml=self.ng_xml
328
- xml.search('/contentMetadata[@type=\''+old_type+'\']').each do |node|
329
- node['type']=new_type
330
- xml.search('//resource[@type=\''+old_resource_type+'\']').each do |resource|
331
- resource['type']=new_resource_type
283
+ xml = ng_xml
284
+ xml.search('/contentMetadata[@type=\'' + old_type + '\']').each do |node|
285
+ node['type'] = new_type
286
+ xml.search('//resource[@type=\'' + old_resource_type + '\']').each do |resource|
287
+ resource['type'] = new_resource_type
332
288
  end
333
289
  end
334
- self.content=xml.to_s
290
+ self.content = xml.to_s
335
291
  end
336
292
  end
337
293
 
338
- end
294
+ end