sufia-models 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72bf8a603a87562ce5ccea4c07d3f798e67e0e1a
4
- data.tar.gz: 36e09e6555144dff4016e718afcb08c3279a28b2
3
+ metadata.gz: f7000540d10c6082fbe78b05a2043eb11f555635
4
+ data.tar.gz: 60e2c7dc3e31acd37648c671f5df9835f151b913
5
5
  SHA512:
6
- metadata.gz: e418a2ce57e7c53a0833f52c458cb4c30079a327c86b48ae3ad5b1de714afa84e886a90d9228c4bbc64749edbbe3cd347d2814a3b5e490b3069d7f8c7f345fba
7
- data.tar.gz: 5c41bf3927b9a23c5fa8541ea5ae8f841253fa3fe76dc532c8ae4b51389d73716b4104627e4348d69cb2c71fe736273b9d9422809ad2de4f062051bc3ad2bbf4
6
+ metadata.gz: 61cb90f5d5c5cbf94aca85a2e23a69f20b03b33105808febb2492c4cc55779c49177abbbcfcbdf65b276617281ccf86eadcb2b55674e2c94130cf4364225c2ed
7
+ data.tar.gz: d0226b74b4c91b7ee635afdf6f37baacd31e8025b53e079a1c123cfa97f1fbd2dfc7851c585f82053e498ab12857600041047d5fce3bbe7541ae69424e762caf
@@ -70,7 +70,11 @@ class FitsDatastream < ActiveFedora::OmDatastream
70
70
  t.offset(:path=>"offset")
71
71
  }
72
72
  t.video {
73
- # Not yet implemented in FITS
73
+ t.width(:path=>"imageWidth")
74
+ t.height(:path=>"imageHeight")
75
+ t.duration(:path=>"duration")
76
+ t.sample_rate(:path=>"sampleRate")
77
+ t.frame_rate(:path=>"frameRate")
74
78
  }
75
79
  }
76
80
  t.format_label(:proxy=>[:identification, :identity, :format_label])
@@ -98,7 +102,9 @@ class FitsDatastream < ActiveFedora::OmDatastream
98
102
  t.byte_order(:proxy=>[:metadata, :image, :byte_order])
99
103
  t.compression(:proxy=>[:metadata, :image, :compression])
100
104
  t.width(:proxy=>[:metadata, :image, :width])
105
+ t.video_width( :proxy=>[:metadata, :video, :width])
101
106
  t.height(:proxy=>[:metadata, :image, :height])
107
+ t.video_height(:proxy=>[:metadata, :video, :height])
102
108
  t.color_space(:proxy=>[:metadata, :image, :color_space])
103
109
  t.profile_name(:proxy=>[:metadata, :image, :profile_name])
104
110
  t.profile_version(:proxy=>[:metadata, :image, :profile_version])
@@ -115,11 +121,14 @@ class FitsDatastream < ActiveFedora::OmDatastream
115
121
  t.markup_basis(:proxy=>[:metadata, :text, :markup_basis])
116
122
  t.markup_language(:proxy=>[:metadata, :text, :markup_language])
117
123
  t.duration(:proxy=>[:metadata, :audio, :duration])
124
+ t.video_duration(:proxy=>[:metadata, :video, :duration])
118
125
  t.bit_depth(:proxy=>[:metadata, :audio, :bit_depth])
119
126
  t.sample_rate(:proxy=>[:metadata, :audio, :sample_rate])
127
+ t.video_sample_rate(:proxy=>[:metadata, :video, :sample_rate])
120
128
  t.channels(:proxy=>[:metadata, :audio, :channels])
121
129
  t.data_format(:proxy=>[:metadata, :audio, :data_format])
122
130
  t.offset(:proxy=>[:metadata, :audio, :offset])
131
+ t.frame_rate(:proxy=>[:metadata, :video, :frame_rate])
123
132
  end
124
133
 
125
134
  def self.xml_template
@@ -55,7 +55,7 @@ This generator makes the following changes to your application:
55
55
  def inject_sufia_user_behavior
56
56
  file_path = "app/models/#{model_name.underscore}.rb"
57
57
  if File.exists?(file_path)
58
- inject_into_class file_path, model_name.classify do
58
+ inject_into_file file_path, after: /include Hydra\:\:User.*$/ do
59
59
  "# Connects this user object to Sufia behaviors. " +
60
60
  "\n include Sufia::User\n"
61
61
  end
@@ -1,3 +1,4 @@
1
+ require 'sufia/virus_found_error'
1
2
  module Sufia
2
3
  module GenericFile
3
4
  extend ActiveSupport::Concern
@@ -9,6 +10,7 @@ module Sufia
9
10
  autoload :Trophies, 'sufia/models/generic_file/trophies'
10
11
  autoload :Metadata, 'sufia/models/generic_file/metadata'
11
12
  autoload :Versions, 'sufia/models/generic_file/versions'
13
+ autoload :VirusCheck, 'sufia/models/generic_file/virus_check'
12
14
  include Sufia::ModelMethods
13
15
  include Sufia::Noid
14
16
  include Sufia::GenericFile::MimeTypes
@@ -22,6 +24,7 @@ module Sufia
22
24
  include Sufia::GenericFile::Trophies
23
25
  include Sufia::GenericFile::Metadata
24
26
  include Sufia::GenericFile::Versions
27
+ include Sufia::GenericFile::VirusCheck
25
28
 
26
29
  included do
27
30
  belongs_to :batch, :property => :is_part_of
@@ -2,7 +2,6 @@ module Sufia::GenericFile
2
2
  # Actions are decoupled from controller logic so that they may be called from a controller or a background job.
3
3
  module Actions
4
4
  def self.create_metadata(generic_file, user, batch_id)
5
-
6
5
  generic_file.apply_depositor_metadata(user)
7
6
  generic_file.date_uploaded = Date.today
8
7
  generic_file.date_modified = Date.today
@@ -16,7 +15,7 @@ module Sufia::GenericFile
16
15
  yield(generic_file) if block_given?
17
16
  generic_file.save!
18
17
  end
19
-
18
+
20
19
  def self.create_content(generic_file, file, file_name, dsid, user)
21
20
  generic_file.add_file(file, dsid, file_name)
22
21
 
@@ -40,15 +39,13 @@ module Sufia::GenericFile
40
39
  end
41
40
 
42
41
  def self.virus_check(file)
43
- if defined? ClamAV
44
- stat = ClamAV.instance.scanfile(file.path)
45
- logger.warn "Virus checking did not pass for #{file.inspect} status = #{stat}" unless stat == 0
46
- stat
47
- else
48
- logger.warn "Virus checking disabled for #{file.inspect}"
49
- 0
42
+ path = file.is_a?(String) ? file : file.path
43
+ unless defined?(ClamAV)
44
+ logger.warn "Virus checking disabled, #{path} not checked"
45
+ return
50
46
  end
51
- end
52
-
47
+ scan_result = ClamAV.instance.scanfile(path)
48
+ raise Sufia::VirusFoundError.new("A virus was found in #{path}: #{scan_result}") unless scan_result == 0
49
+ end
53
50
  end
54
51
  end
@@ -13,21 +13,36 @@ module Sufia
13
13
  :file_language, :word_count, :character_count,
14
14
  :paragraph_count, :line_count, :table_count,
15
15
  :graphics_count, :byte_order, :compression,
16
- :width, :height, :color_space, :profile_name,
16
+ :color_space, :profile_name,
17
17
  :profile_version, :orientation, :color_map,
18
18
  :image_producer, :capture_device,
19
19
  :scanning_software, :exif_version,
20
20
  :gps_timestamp, :latitude, :longitude,
21
21
  :character_set, :markup_basis,
22
- :markup_language, :duration, :bit_depth,
23
- :sample_rate, :channels, :data_format, :offset, datastream: :characterization, multiple: true
22
+ :markup_language, :bit_depth,
23
+ :channels, :data_format, :offset, :frame_rate, datastream: :characterization, multiple: true
24
24
 
25
25
  end
26
26
 
27
+ def width
28
+ characterization.width.blank? ? characterization.video_width : characterization.width
29
+ end
30
+
31
+ def height
32
+ characterization.height.blank? ? characterization.video_height : characterization.height
33
+ end
34
+
35
+ def duration
36
+ characterization.duration.blank? ? characterization.video_duration : characterization.duration
37
+ end
38
+
39
+ def sample_rate
40
+ characterization.sample_rate.blank? ? characterization.video_sample_rate : characterization.sample_rate
41
+ end
42
+
27
43
  def characterize_if_changed
28
44
  content_changed = self.content.changed?
29
45
  yield
30
- #logger.debug "DOING CHARACTERIZE ON #{self.pid}"
31
46
  Sufia.queue.push(CharacterizeJob.new(self.pid)) if content_changed
32
47
  end
33
48
 
@@ -0,0 +1,33 @@
1
+ module Sufia
2
+ module GenericFile
3
+ module VirusCheck
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ validate :detect_viruses
8
+ end
9
+
10
+ # Default behavior is to raise a validation error and halt the save if a virus is found
11
+ def detect_viruses
12
+ return unless content.changed?
13
+ path = if content.content.respond_to?(:path)
14
+ content.content.path
15
+ else
16
+ Tempfile.open('') do |t|
17
+ t.binmode
18
+ t.write(content.content)
19
+ t.close
20
+ t.path
21
+ end
22
+ end
23
+ Sufia::GenericFile::Actions.virus_check(path)
24
+ true
25
+ rescue Sufia::VirusFoundError => virus
26
+ logger.warn(virus.message)
27
+ errors.add(:content, virus.message)
28
+ false
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -22,14 +22,13 @@ module Sufia
22
22
  end
23
23
 
24
24
  def terms_for_editing
25
- terms_for_display -
26
- [:part_of, :date_modified, :date_uploaded, :format] #, :resource_type]
25
+ terms_for_display - [:date_modified, :date_uploaded, :format]
27
26
  end
28
27
 
29
28
  def terms_for_display
30
29
  # 'type' is the RDF.type assertion, which is not present by default, but may be
31
30
  # provided in some RDF schemas
32
- self.descMetadata.class.fields
31
+ self.descMetadata.class.fields - [:part_of]
33
32
  end
34
33
 
35
34
  def to_jq_upload
@@ -9,40 +9,38 @@ class ImportUrlJob < ActiveFedoraPidBasedJob
9
9
  end
10
10
 
11
11
  def run
12
- f = Tempfile.new(self.pid)
13
- f.binmode
14
-
15
- # download file from url
16
- uri = URI(generic_file.import_url)
17
- http = Net::HTTP.new(uri.host, uri.port)
18
- http.use_ssl = uri.scheme == "https" # enable SSL/TLS
19
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
20
-
21
- http.start do
22
- http.request_get(uri.request_uri) do |resp|
23
- resp.read_body do |segment|
24
- f.write(segment)
12
+ user = User.find_by_user_key(generic_file.depositor)
13
+
14
+ Tempfile.open(self.pid) do |f|
15
+ f.binmode
16
+
17
+ # download file from url
18
+ uri = URI(generic_file.import_url)
19
+ http = Net::HTTP.new(uri.host, uri.port)
20
+ http.use_ssl = uri.scheme == "https" # enable SSL/TLS
21
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
22
+
23
+ http.start do
24
+ http.request_get(uri.request_uri) do |resp|
25
+ resp.read_body do |segment|
26
+ f.write(segment)
27
+ end
25
28
  end
26
29
  end
27
- end
28
- job_user = User.batchuser()
29
- user = User.find_by_user_key(generic_file.depositor)
30
- # check for virus
31
- if Sufia::GenericFile::Actions.virus_check(f) != 0
32
- message = "The file (#{File.basename(uri.path)}) was unable to be imported because it contained a virus."
33
- job_user.send_message(user, message, 'File Import Error')
34
- return
30
+
31
+ f.rewind
32
+ # attach downloaded file to generic file stubbed out
33
+ Sufia::GenericFile::Actions.create_content(generic_file, f, File.basename(uri.path), 'content', user)
34
+ Sufia.queue.push(ContentDepositEventJob.new(generic_file.pid, generic_file.depositor))
35
+ # add message to user for downloaded file
36
+ message = "The file (#{File.basename(uri.path)}) was successfully imported."
37
+ job_user.send_message(user, message, 'File Import')
35
38
  end
39
+ rescue => error
40
+ job_user.send_message(user, error.message, 'File Import Error')
41
+ end
36
42
 
37
- f.rewind
38
- # attach downloaded file to generic file stubbed out
39
- Sufia::GenericFile::Actions.create_content(generic_file, f, File.basename(uri.path), 'content', user)
40
- # add message to user for downloaded file
41
- message = "The file (#{File.basename(uri.path)}) was successfully imported."
42
- job_user.send_message(user, message, 'File Import')
43
-
44
- ensure
45
- f.close
46
- f.unlink
43
+ def job_user
44
+ User.batchuser
47
45
  end
48
46
  end
@@ -1,5 +1,5 @@
1
1
  module Sufia
2
2
  module Models
3
- VERSION = "3.4.0"
3
+ VERSION = "3.5.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sufia-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -333,6 +333,7 @@ files:
333
333
  - lib/sufia/models/generic_file/thumbnail.rb
334
334
  - lib/sufia/models/generic_file/trophies.rb
335
335
  - lib/sufia/models/generic_file/versions.rb
336
+ - lib/sufia/models/generic_file/virus_check.rb
336
337
  - lib/sufia/models/generic_file/web_form.rb
337
338
  - lib/sufia/models/id_service.rb
338
339
  - lib/sufia/models/jobs/active_fedora_pid_based_job.rb
@@ -374,7 +375,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
374
375
  version: '0'
375
376
  requirements: []
376
377
  rubyforge_project:
377
- rubygems_version: 2.0.3
378
+ rubygems_version: 2.0.14
378
379
  signing_key:
379
380
  specification_version: 4
380
381
  summary: Models and services for sufia