hydra-core 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ # model for a FileAsset ActiveFedora object
2
+ # a file asset is a generic notion of a file, which could have, for example, image or text or video behaviors.
3
+ class FileAsset < ActiveFedora::Base
4
+ include Hydra::Models::FileAsset
5
+ end
@@ -1,4 +1,4 @@
1
1
  module HydraHead
2
- VERSION = "5.1.0"
2
+ VERSION = "5.2.0"
3
3
  end
4
4
 
@@ -9,9 +9,10 @@ module Hydra::Controller::UploadBehavior
9
9
  if params.has_key?(:Filedata)
10
10
  @file_assets = []
11
11
  params[:Filedata].each do |file|
12
- @file_asset = create_asset_from_file(file)
13
- add_posted_blob_to_asset(@file_asset,file)
14
- @file_asset.save
12
+ @file_asset = FileAsset.new
13
+ @file_asset.label = file.original_filename
14
+ add_posted_blob_to_asset(@file_asset, file, file.original_filename)
15
+ @file_asset.save!
15
16
  @file_assets << @file_asset
16
17
  end
17
18
  return @file_assets
@@ -24,10 +25,13 @@ module Hydra::Controller::UploadBehavior
24
25
  # Sets asset label and title to filename if they're empty
25
26
  #
26
27
  # @param [FileAsset] asset the File Asset to add the blob to
28
+ # @param [#read] file the IO object that is the blob
29
+ # @param [String] file the IO object that is the blob
27
30
  # @return [FileAsset] file the File Asset
28
- def add_posted_blob_to_asset(asset, file)
29
- #file_name = filename_from_params
30
- file_name = file.original_filename
31
+ def add_posted_blob_to_asset(asset, file, file_name = nil)
32
+ # deprecating 2 argument constructor because it depends on a HTTP request. If we pass the file name we can use for non-web too.
33
+ Deprecation.warn(Hydra::Controller::UploadBehavior, "add_posted_blob_to_asset with a 2 argument constructor is deprecated. Pass a filename (e.g. \"file.original_name\") as the third argument. 2 argument constructor will be removed in hydra-core 6" ) if file_name.nil?
34
+ file_name ||= file.original_filename
31
35
  options = {:label=>file_name, :mimeType=>mime_type(file_name)}
32
36
  dsid = datastream_id #Only call this once so that it could be a sequence
33
37
  options[:dsid] = dsid if dsid
@@ -53,81 +57,7 @@ module Hydra::Controller::UploadBehavior
53
57
  end
54
58
  deprecation_deprecate :associate_file_asset_with_container
55
59
 
56
- # Apply any posted file metadata to the file asset
57
- def apply_posted_file_metadata
58
- @metadata_update_response = update_document(@file_asset, @sanitized_params)
59
- @file_asset.save
60
- end
61
-
62
-
63
- # The posted File
64
- # @return [File] the posted file. Defaults to nil if no file was posted.
65
- def posted_file
66
- params[:Filedata]
67
- end
68
60
 
69
- # A best-guess filename based on POST params
70
- # If Filename was submitted, it uses that. Otherwise, it calls +original_filename+ on the posted file
71
- def filename_from_params
72
- if !params[:Filename].nil?
73
- file_name = params[:Filename]
74
- else
75
- file_name = posted_file.original_filename
76
- params[:Filename] = file_name
77
- end
78
- end
79
-
80
- # Creates a File Asset and sets its label from params[:Filename]
81
- #
82
- # @return [FileAsset] the File Asset
83
- def create_asset_from_params
84
- file_asset = FileAsset.new
85
- file_asset.label = params[:Filename]
86
-
87
- return file_asset
88
- end
89
-
90
- # Creates a File Asset and sets its label from filename
91
- #
92
- # @return [FileAsset] the File Asset
93
- def create_asset_from_file(file)
94
- file_asset = FileAsset.new
95
- file_asset.label = file.original_filename
96
-
97
- return file_asset
98
- end
99
-
100
-
101
- # This is pre-Hydra code that created an AudioAsset, VideoAsset or ImageAsset based on the
102
- # current params in the controller.
103
- #
104
- # @return [Constant] the recommended Asset class
105
- def asset_class_from_params
106
- if params.has_key?(:type)
107
- chosen_type = case params[:type]
108
- when "AudioAsset"
109
- AudioAsset
110
- when "VideoAsset"
111
- VideoAsset
112
- when "ImageAsset"
113
- ImageAsset
114
- else
115
- FileAsset
116
- end
117
- elsif params.has_key?(:Filename)
118
- chosen_type = choose_model_by_filename( params[:Filename] )
119
- else
120
- chosen_type = FileAsset
121
- end
122
-
123
- return chosen_type
124
- end
125
-
126
- def choose_model_by_filename(filename)
127
- choose_model_by_filename_extension( File.extname(filename) )
128
- end
129
-
130
-
131
61
  private
132
62
  # Return the mimeType for a given file name
133
63
  # @param [String] file_name The filename to use to get the mimeType
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Controller::UploadBehavior do
4
+
5
+ it "should respond to datastream_id" do
6
+ helper.should respond_to :datastream_id ### API method, test that it's there to be overridden
7
+ end
8
+
9
+ describe "add_posted_blob_to_asset" do
10
+ it "should set object title and label, relying on datastream_id to set dsId" do
11
+ mock_file = mock("File")
12
+ file_name = "Posted Filename.foo"
13
+ helper.stub(:params).and_return( :Filedata=>[mock_file], :Filename=>file_name, "container_id"=>"hydrangea:2973" )
14
+ mock_fa = mock("file asset")
15
+ mock_file.should_receive(:original_filename).and_return(file_name)
16
+ helper.stub(:datastream_id).and_return('bar')
17
+ mock_fa.should_receive(:add_file_datastream).with(mock_file, :label=>file_name, :mimeType=>"mymimetype", :dsid=>'bar')
18
+ mock_fa.should_receive(:set_title_and_label).with( file_name, :only_if_blank=>true )
19
+ helper.should_receive(:mime_type).with(file_name).and_return("mymimetype")
20
+ helper.add_posted_blob_to_asset(mock_fa,mock_file) # this is the deprecated 2 argument method
21
+ end
22
+
23
+ it "should support submissions from swfupload" do
24
+ mock_file = mock("File")
25
+ file_name = "Posted Filename.foo"
26
+ helper.stub(:params).and_return( :Filedata=>[mock_file], :Filename=>file_name, "container_id"=>"hydrangea:2973" )
27
+ mock_fa = mock("file asset")
28
+ mock_file.should_receive(:original_filename).and_return(file_name)
29
+ mock_fa.should_receive(:add_file_datastream).with(mock_file, :label=>file_name, :mimeType=>"mymimetype", :dsid => 'content')
30
+ mock_fa.stub(:set_title_and_label)
31
+ helper.should_receive(:mime_type).with(file_name).and_return("mymimetype")
32
+ helper.add_posted_blob_to_asset(mock_fa,mock_file)
33
+ end
34
+ it "should support submissions from single-file uploader, defaulting to dsId of content" do
35
+ mock_file = mock("File")
36
+ file_name = "Posted Filename.foo"
37
+ helper.stub(:params).and_return( :Filedata=>[mock_file], :container_id=>"hydrangea:2973" )
38
+ mock_file.should_receive(:original_filename).and_return(file_name)
39
+ mock_fa = mock("file asset")
40
+ helper.should_receive(:mime_type).with(file_name).and_return("mymimetype")
41
+ mock_fa.should_receive(:add_file_datastream).with(mock_file, :label=>file_name, :mimeType=>"mymimetype", :dsid => 'content')
42
+ mock_fa.stub(:set_title_and_label)
43
+ helper.add_posted_blob_to_asset(mock_fa,mock_file)
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-20 00:00:00.000000000 Z
13
+ date: 2013-01-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -179,7 +179,7 @@ dependencies:
179
179
  requirements:
180
180
  - - '='
181
181
  - !ruby/object:Gem::Version
182
- version: 5.1.0
182
+ version: 5.2.0
183
183
  type: :runtime
184
184
  prerelease: false
185
185
  version_requirements: !ruby/object:Gem::Requirement
@@ -187,7 +187,7 @@ dependencies:
187
187
  requirements:
188
188
  - - '='
189
189
  - !ruby/object:Gem::Version
190
- version: 5.1.0
190
+ version: 5.2.0
191
191
  - !ruby/object:Gem::Dependency
192
192
  name: sqlite3
193
193
  requirement: !ruby/object:Gem::Requirement
@@ -315,6 +315,7 @@ files:
315
315
  - app/helpers/facets_helper.rb
316
316
  - app/helpers/hydra/blacklight_helper_behavior.rb
317
317
  - app/helpers/hydra/facets_helper_behavior.rb
318
+ - app/models/file_asset.rb
318
319
  - app/models/hydra/datastream/properties.rb
319
320
  - app/models/mods_asset.rb
320
321
  - config/jetty.yml
@@ -366,6 +367,7 @@ files:
366
367
  - spec/factories.rb
367
368
  - spec/helpers/blacklight_helper_spec.rb
368
369
  - spec/helpers/facets_helper_spec.rb
370
+ - spec/helpers/upload_behavior_spec.rb
369
371
  - spec/lib/catalog_spec.rb
370
372
  - spec/lib/global_configurable_spec.rb
371
373
  - spec/lib/model_methods_spec.rb
@@ -424,6 +426,7 @@ test_files:
424
426
  - spec/factories.rb
425
427
  - spec/helpers/blacklight_helper_spec.rb
426
428
  - spec/helpers/facets_helper_spec.rb
429
+ - spec/helpers/upload_behavior_spec.rb
427
430
  - spec/lib/catalog_spec.rb
428
431
  - spec/lib/global_configurable_spec.rb
429
432
  - spec/lib/model_methods_spec.rb