sufia 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -2
- data/History.md +6 -0
- data/README.md +40 -0
- data/Rakefile +4 -0
- data/app/assets/javascripts/sufia.js +3 -115
- data/app/assets/javascripts/sufia/batch_select_all.js +179 -0
- data/app/assets/javascripts/sufia/edit_metadata.js +86 -0
- data/app/assets/javascripts/sufia/multiForm.js +57 -0
- data/app/assets/javascripts/terms_of_service.js +7 -0
- data/app/assets/stylesheets/audio-js.css +3 -0
- data/app/assets/stylesheets/dashboard.css.scss +51 -0
- data/app/assets/stylesheets/generic_files.css +36 -0
- data/app/assets/stylesheets/sufia.css.scss +2 -0
- data/app/controllers/batch_controller.rb +11 -0
- data/app/controllers/batch_edits_controller.rb +1 -77
- data/app/controllers/generic_files_controller.rb +1 -0
- data/app/controllers/mailbox_controller.rb +1 -1
- data/app/controllers/single_use_link_controller.rb +11 -7
- data/app/helpers/generic_file_helper.rb +11 -3
- data/app/helpers/sufia_helper.rb +13 -10
- data/app/models/batch.rb +1 -1
- data/app/models/datastreams/fits_datastream.rb +2 -2
- data/app/models/datastreams/generic_file_rdf_datastream.rb +22 -18
- data/app/models/datastreams/properties_datastream.rb +2 -2
- data/app/views/_user_util_links.html.erb +2 -2
- data/app/views/batch/_metadata.html.erb +82 -0
- data/app/views/batch/_more_metadata.html.erb +6 -0
- data/app/views/batch/edit.html.erb +1 -8
- data/app/views/batch_edits/_check_all.html.erb +0 -157
- data/app/views/batch_edits/edit.html.erb +0 -29
- data/app/views/catalog/_index_partials/_list_files.html.erb +8 -10
- data/app/views/catalog/_recent_document.html.erb +9 -18
- data/app/views/catalog/_results_pagination.html.erb +1 -1
- data/app/views/contact_form/new.html.erb +1 -1
- data/app/views/dashboard/_index_partials/_default_group.html.erb +1 -1
- data/app/views/dashboard/_index_partials/_list_files.html.erb +12 -14
- data/app/views/dashboard/_index_partials/_thumbnail_display.html.erb +9 -19
- data/app/views/dashboard/_results_pagination.html.erb +1 -1
- data/app/views/dashboard/index.html.erb +6 -82
- data/app/views/error/single_use_error.html.erb +35 -0
- data/app/views/generic_files/_descriptions.html.erb +2 -2
- data/app/views/generic_files/_extra_fields_modal.html.erb +1 -1
- data/app/views/generic_files/_field_form.html.erb +2 -5
- data/app/views/generic_files/_media_display.html.erb +8 -6
- data/app/views/generic_files/_permission.html.erb +2 -2
- data/app/views/generic_files/_rights_modal.html.erb +1 -1
- data/app/views/generic_files/_show_actions.html.erb +1 -1
- data/app/views/generic_files/_show_details.html.erb +11 -6
- data/app/views/generic_files/edit.html.erb +0 -8
- data/app/views/generic_files/edit_fields/_type.html.erb +1 -1
- data/app/views/generic_files/show.html.erb +5 -8
- data/app/views/generic_files/show_fields/_based_near.html.erb +4 -1
- data/app/views/generic_files/show_fields/_contributor.html.erb +4 -1
- data/app/views/generic_files/show_fields/_creator.html.erb +4 -1
- data/app/views/generic_files/show_fields/_date_created.html.erb +4 -1
- data/app/views/generic_files/show_fields/_description.html.erb +4 -1
- data/app/views/generic_files/show_fields/_language.html.erb +1 -1
- data/app/views/generic_files/show_fields/_publisher.html.erb +4 -1
- data/app/views/generic_files/show_fields/_related_url.html.erb +3 -1
- data/app/views/generic_files/show_fields/_resource_type.html.erb +1 -1
- data/app/views/generic_files/show_fields/_subject.html.erb +4 -1
- data/app/views/generic_files/show_fields/_tag.html.erb +1 -1
- data/app/views/generic_files/show_fields/_title.html.erb +4 -1
- data/app/views/layouts/error.html.erb +0 -4
- data/app/views/layouts/hydra-head.html.erb +2 -6
- data/app/views/single_use_link/show.html.erb +1 -1
- data/app/views/users/index.html.erb +1 -1
- data/app/views/users/show.html.erb +1 -1
- data/config/locales/sufia.en.yml +1 -0
- data/config/routes.rb +11 -4
- data/lib/generators/sufia/sufia_generator.rb +2 -1
- data/lib/generators/sufia/templates/catalog_controller.rb +143 -117
- data/lib/generators/sufia/templates/config/resque_admin.rb +10 -0
- data/lib/generators/sufia/templates/config/sufia.rb +8 -0
- data/lib/sufia.rb +4 -14
- data/lib/sufia/batch_edits_controller_behavior.rb +89 -0
- data/lib/sufia/controller.rb +7 -5
- data/lib/sufia/downloads_controller_behavior.rb +14 -19
- data/lib/sufia/file_content/extract_metadata.rb +11 -4
- data/lib/sufia/files_controller_behavior.rb +63 -44
- data/lib/sufia/generic_file.rb +29 -11
- data/lib/sufia/generic_file/audit.rb +1 -1
- data/lib/sufia/generic_file/thumbnail.rb +51 -26
- data/lib/sufia/id_service.rb +28 -11
- data/lib/sufia/jobs/batch_update_job.rb +2 -2
- data/lib/sufia/jobs/characterize_job.rb +11 -3
- data/lib/sufia/jobs/ffmpeg_transcode_job.rb +61 -0
- data/lib/sufia/jobs/resolrize_job.rb +1 -1
- data/lib/sufia/jobs/transcode_audio_job.rb +40 -0
- data/lib/sufia/jobs/transcode_video_job.rb +9 -49
- data/lib/sufia/queue/resque.rb +2 -2
- data/lib/sufia/single_use_error.rb +4 -0
- data/lib/sufia/solr_document_behavior.rb +108 -1
- data/lib/sufia/version.rb +1 -1
- data/solr_conf/conf/schema.xml +332 -652
- data/solr_conf/conf/solrconfig.xml +60 -196
- data/spec/controllers/batch_controller_spec.rb +4 -5
- data/spec/controllers/catalog_controller_spec.rb +13 -13
- data/spec/controllers/dashboard_controller_spec.rb +2 -2
- data/spec/controllers/downloads_controller_spec.rb +74 -62
- data/spec/controllers/generic_files_controller_spec.rb +10 -8
- data/spec/controllers/single_use_link_controller_spec.rb +12 -4
- data/spec/fixtures/Example.ogg +0 -0
- data/spec/fixtures/piano_note.wav +0 -0
- data/spec/fixtures/sufia_generic_stub.descMeta.txt +1 -1
- data/spec/helpers/sufia_helper_spec.rb +12 -0
- data/spec/models/characterize_job_spec.rb +89 -0
- data/spec/models/checksum_audit_log_spec.rb +1 -0
- data/spec/models/event_jobs_spec.rb +9 -9
- data/spec/models/file_content_datastream_spec.rb +16 -10
- data/spec/models/fits_datastream_spec.rb +2 -8
- data/spec/models/generic_file_spec.rb +131 -60
- data/spec/models/solr_document_spec.rb +21 -0
- data/spec/models/transcode_audio_job_spec.rb +81 -0
- data/spec/models/transcode_video_job_spec.rb +2 -2
- data/spec/models/unzip_job_spec.rb +3 -3
- data/spec/spec_helper.rb +21 -0
- data/spec/support/Gemfile +7 -3
- data/sufia.gemspec +8 -11
- data/tasks/cucumber.rake +1 -2
- data/tasks/sufia-dev.rake +13 -2
- data/tasks/sufia.rake +1 -1
- metadata +77 -118
- data/app/views/batch_edits/_metadata.html.erb +0 -180
- data/lib/generators/sufia/templates/config/hydra_config.rb +0 -32
- data/lib/kaminari/helpers/tag.rb +0 -11
@@ -0,0 +1,10 @@
|
|
1
|
+
module Sufia
|
2
|
+
class ResqueAdmin
|
3
|
+
def self.matches?(request)
|
4
|
+
current_user = request.env['warden'].user
|
5
|
+
return false if current_user.blank?
|
6
|
+
# TODO code a group here that makes sense
|
7
|
+
#current_user.groups.include? 'umg/up.dlt.scholarsphere-admin'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -61,6 +61,14 @@ Sufia.config do |config|
|
|
61
61
|
# Map hostnames onto Google Analytics tracking IDs
|
62
62
|
#config.google_analytics_id = 'UA-99999999-1'
|
63
63
|
|
64
|
+
|
65
|
+
# Where to store tempfiles, leave blank for the system temp directory (e.g. /tmp)
|
66
|
+
#config.temp_file_base = '/home/developer1'
|
67
|
+
|
68
|
+
# If you have ffmpeg installed and want to transcode audio and video uncomment this line
|
69
|
+
#config.enable_ffmpeg = true
|
70
|
+
|
64
71
|
end
|
65
72
|
|
73
|
+
Date::DATE_FORMATS[:standard] = "%m/%d/%Y"
|
66
74
|
|
data/lib/sufia.rb
CHANGED
@@ -24,10 +24,12 @@ module Sufia
|
|
24
24
|
class Engine < ::Rails::Engine
|
25
25
|
engine_name 'sufia'
|
26
26
|
|
27
|
+
# Set some configuration defaults
|
27
28
|
config.queue = Sufia::Resque::Queue
|
29
|
+
config.enable_ffmpeg = false
|
28
30
|
config.ffmpeg_path = 'ffmpeg'
|
29
31
|
config.fits_message_length = 5
|
30
|
-
|
32
|
+
config.temp_file_base = nil
|
31
33
|
|
32
34
|
config.autoload_paths << File.expand_path("../sufia/jobs", __FILE__)
|
33
35
|
|
@@ -35,25 +37,12 @@ module Sufia
|
|
35
37
|
require 'sufia/active_fedora/redis'
|
36
38
|
end
|
37
39
|
|
38
|
-
initializer "Patch kaminari" do
|
39
|
-
require "kaminari/helpers/tag"
|
40
|
-
end
|
41
|
-
|
42
40
|
initializer "Patch active_record" do
|
43
41
|
require 'sufia/active_record/redis'
|
44
42
|
end
|
45
43
|
|
46
44
|
end
|
47
45
|
|
48
|
-
class ResqueAdmin
|
49
|
-
def self.matches?(request)
|
50
|
-
current_user = request.env['warden'].user
|
51
|
-
return false if current_user.blank?
|
52
|
-
# TODO code a group here that makes sense
|
53
|
-
#current_user.groups.include? 'umg/up.dlt.scholarsphere-admin'
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
46
|
def self.config(&block)
|
58
47
|
@@config ||= Sufia::Engine::Configuration.new
|
59
48
|
|
@@ -76,6 +65,7 @@ module Sufia
|
|
76
65
|
autoload :HttpHeaderAuth
|
77
66
|
autoload :SolrDocumentBehavior
|
78
67
|
autoload :FilesControllerBehavior
|
68
|
+
autoload :BatchEditsControllerBehavior
|
79
69
|
autoload :DownloadsControllerBehavior
|
80
70
|
autoload :FileContent
|
81
71
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Sufia
|
2
|
+
module BatchEditsControllerBehavior
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def edit
|
6
|
+
super
|
7
|
+
@generic_file = ::GenericFile.new
|
8
|
+
@generic_file.depositor = current_user.user_key
|
9
|
+
@terms = @generic_file.terms_for_editing - [:title, :format, :resource_type]
|
10
|
+
|
11
|
+
# do we want to show the original values for anything...
|
12
|
+
@show_file = ::GenericFile.new
|
13
|
+
@show_file.depositor = current_user.user_key
|
14
|
+
h = {}
|
15
|
+
@names = []
|
16
|
+
permissions = []
|
17
|
+
|
18
|
+
# For each of the files in the batch, set the attributes to be the concatination of all the attributes
|
19
|
+
batch.each do |doc_id|
|
20
|
+
gf = ::GenericFile.find(doc_id)
|
21
|
+
gf.terms_for_editing.each do |key|
|
22
|
+
h[key] ||= []
|
23
|
+
h[key] = (h[key] + gf.send(key)).uniq
|
24
|
+
end
|
25
|
+
@names << display_title(gf)
|
26
|
+
permissions = (permissions+gf.permissions).uniq
|
27
|
+
end
|
28
|
+
|
29
|
+
initialize_fields(h, @show_file)
|
30
|
+
|
31
|
+
# map the permissions to parameter like input so that the assign will work
|
32
|
+
# todo sort the access level some how...
|
33
|
+
perm_param ={'user'=>{},'group'=>{"public"=>"1"}}
|
34
|
+
permissions.each{ |perm| perm_param[perm[:type]][perm[:name]] = perm[:access]}
|
35
|
+
@show_file.permissions = HashWithIndifferentAccess.new(perm_param)
|
36
|
+
end
|
37
|
+
|
38
|
+
def after_update
|
39
|
+
redirect_to sufia.dashboard_index_path unless request.xhr?
|
40
|
+
end
|
41
|
+
|
42
|
+
def update_document(obj)
|
43
|
+
super
|
44
|
+
obj.date_modified = Time.now.ctime
|
45
|
+
obj.set_visibility(params[:visibility])
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
# keep the batch around if we are doing ajax calls
|
50
|
+
batch_sav = batch.dup if request.xhr?
|
51
|
+
catalog_index_path = sufia.dashboard_index_path
|
52
|
+
type = params["update_type"]
|
53
|
+
if (type == "update")
|
54
|
+
#params["generic_file"].reject! {|k,v| (v.blank? || (v.respond_to?(:length) && v.length==1 && v.first.blank?))}
|
55
|
+
super
|
56
|
+
elsif (type == "delete_all")
|
57
|
+
batch.each do |doc_id|
|
58
|
+
gf = ::GenericFile.find(doc_id)
|
59
|
+
gf.delete
|
60
|
+
end
|
61
|
+
clear_batch!
|
62
|
+
after_update
|
63
|
+
end
|
64
|
+
|
65
|
+
# reset the batch around if we are doing ajax calls
|
66
|
+
if request.xhr?
|
67
|
+
self.batch = batch_sav.dup
|
68
|
+
@key = params["key"]
|
69
|
+
if (@key != "permissions")
|
70
|
+
@vals = params["generic_file"][@key]
|
71
|
+
else
|
72
|
+
@vals = [""]
|
73
|
+
end
|
74
|
+
render :update_edit
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
# override this method if you need to initialize more complex RDF assertions (b-nodes)
|
81
|
+
def initialize_fields(attributes, file)
|
82
|
+
file.terms_for_editing.each do |key|
|
83
|
+
# if value is empty, we create an one element array to loop over for output
|
84
|
+
file[key] = attributes[key].empty? ? [''] : attributes[key]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
data/lib/sufia/controller.rb
CHANGED
@@ -25,11 +25,11 @@ module Sufia::Controller
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def current_ability
|
28
|
-
|
28
|
+
user_signed_in? ? current_user.ability : super
|
29
29
|
end
|
30
30
|
|
31
31
|
def groups
|
32
|
-
@groups ||=
|
32
|
+
@groups ||= user_signed_in? ? current_user.groups : []
|
33
33
|
end
|
34
34
|
|
35
35
|
def render_404(exception)
|
@@ -42,12 +42,16 @@ module Sufia::Controller
|
|
42
42
|
render :template => '/error/500', :layout => "error", :formats => [:html], :status => 500
|
43
43
|
end
|
44
44
|
|
45
|
+
def render_single_use_error(exception)
|
46
|
+
logger.error("Rendering PAGE due to exception: #{exception.inspect} - #{exception.backtrace if exception.respond_to? :backtrace}")
|
47
|
+
render :template => '/error/single_use_error', :layout => "error", :formats => [:html], :status => 404
|
48
|
+
end
|
45
49
|
|
46
50
|
def notifications_number
|
47
51
|
@notify_number=0
|
48
52
|
@batches=[]
|
49
53
|
return if action_name == "index" && controller_name == "mailbox"
|
50
|
-
if
|
54
|
+
if user_signed_in?
|
51
55
|
@notify_number= current_user.mailbox.inbox(:unread => true).count(:id, :distinct => true)
|
52
56
|
@batches=current_user.mailbox.inbox.map {|msg| msg.last_message.body[/<a class="batchid ui-helper-hidden">(.*)<\/a>The file(.*)/,1]}.select{|val| !val.blank?}
|
53
57
|
end
|
@@ -60,6 +64,4 @@ module Sufia::Controller
|
|
60
64
|
true
|
61
65
|
end
|
62
66
|
|
63
|
-
# include Sufia::HttpHeaderAuth
|
64
|
-
|
65
67
|
end
|
@@ -36,36 +36,31 @@ module Sufia
|
|
36
36
|
end
|
37
37
|
|
38
38
|
protected
|
39
|
-
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
|
40
|
+
def datastream_name
|
41
|
+
@datastream_name ||= params[:datastream_id] || DownloadsController.default_content_dsid
|
42
|
+
end
|
43
|
+
|
44
|
+
def send_content(asset)
|
45
|
+
opts = {disposition: 'inline'}
|
46
|
+
if default_datastream?
|
47
|
+
opts[:filename] = params["filename"] || asset.label
|
48
|
+
else
|
46
49
|
opts[:filename] = params[:datastream_id]
|
47
|
-
ds = asset.datastreams[params[:datastream_id]]
|
48
50
|
end
|
49
|
-
ds =
|
51
|
+
ds = asset.datastreams[datastream_name]
|
50
52
|
raise ActionController::RoutingError.new('Not Found') if ds.nil?
|
51
53
|
data = ds.content
|
52
54
|
opts[:type] = ds.mimeType
|
53
55
|
send_data data, opts
|
54
|
-
return
|
55
56
|
end
|
56
57
|
|
58
|
+
def default_datastream?
|
59
|
+
datastream_name == self.class.default_content_dsid
|
60
|
+
end
|
57
61
|
|
58
62
|
private
|
59
63
|
|
60
|
-
def default_content_ds(asset)
|
61
|
-
ActiveFedora::ContentModel.known_models_for(asset).each do |model_class|
|
62
|
-
return model_class.default_content_ds if model_class.respond_to?(:default_content_ds)
|
63
|
-
end
|
64
|
-
if asset.datastreams.keys.include?(DownloadsController.default_content_dsid)
|
65
|
-
return asset.datastreams[DownloadsController.default_content_dsid]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
64
|
module ClassMethods
|
70
65
|
def default_content_dsid
|
71
66
|
"content"
|
@@ -13,7 +13,8 @@ module Sufia
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def to_tempfile &block
|
16
|
-
return
|
16
|
+
return unless has_content?
|
17
|
+
tmp_base = Sufia::Engine.config.temp_file_base
|
17
18
|
f = Tempfile.new("#{pid}-#{dsVersionID}")
|
18
19
|
f.binmode
|
19
20
|
if content.respond_to? :read
|
@@ -25,21 +26,27 @@ module Sufia
|
|
25
26
|
content.rewind if content.respond_to? :rewind
|
26
27
|
yield(f)
|
27
28
|
f.unlink
|
29
|
+
end
|
28
30
|
|
31
|
+
# Return true if the content is present
|
32
|
+
# You can override this method if your content is an external datastream
|
33
|
+
def has_content?
|
34
|
+
!content.nil?
|
29
35
|
end
|
30
36
|
|
31
37
|
private
|
32
38
|
|
33
39
|
|
34
40
|
def run_fits!(file_path)
|
35
|
-
command = "#{fits_path} -i #{file_path}"
|
36
|
-
stdin, stdout, stderr = popen3(command)
|
41
|
+
command = "#{fits_path} -i \"#{file_path}\""
|
42
|
+
stdin, stdout, stderr, wait_thr = popen3(command)
|
37
43
|
stdin.close
|
38
44
|
out = stdout.read
|
39
45
|
stdout.close
|
40
46
|
err = stderr.read
|
41
47
|
stderr.close
|
42
|
-
|
48
|
+
exit_status = wait_thr.value
|
49
|
+
raise "Unable to execute command \"#{command}\"\n#{err}" unless exit_status.success?
|
43
50
|
out
|
44
51
|
end
|
45
52
|
|
@@ -53,7 +53,7 @@ module Sufia
|
|
53
53
|
|
54
54
|
# routed to /files/:id/edit
|
55
55
|
def edit
|
56
|
-
@
|
56
|
+
initialize_fields(@generic_file)
|
57
57
|
@groups = current_user.groups
|
58
58
|
end
|
59
59
|
|
@@ -74,55 +74,26 @@ module Sufia
|
|
74
74
|
# routed to /files (POST)
|
75
75
|
def create
|
76
76
|
begin
|
77
|
-
retval = " "
|
78
77
|
# check error condition No files
|
79
|
-
return
|
78
|
+
return json_error("Error! No file to save") if !params.has_key?(:files)
|
80
79
|
|
81
80
|
file = params[:files].detect {|f| f.respond_to?(:original_filename) }
|
82
81
|
if !file
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
if ((file.respond_to?(:tempfile)) && (file.tempfile.size == 0))
|
89
|
-
retval = render :json => [{ :name => file.original_filename, :error => "Error! Zero Length File!"}].to_json
|
90
|
-
elsif ((file.respond_to?(:size)) && (file.size == 0))
|
91
|
-
retval = render :json => [{ :name => file.original_filename, :error => "Error! Zero Length File!"}].to_json
|
92
|
-
elsif (params[:terms_of_service] != '1')
|
93
|
-
retval = render :json => [{ :name => file.original_filename, :error => "You must accept the terms of service!"}].to_json
|
94
|
-
|
95
|
-
# process file
|
82
|
+
json_error "Error! No file for upload", 'unknown file', :status => :unprocessable_entity
|
83
|
+
elsif (empty_file?(file))
|
84
|
+
json_error "Error! Zero Length File!", file.original_filename
|
85
|
+
elsif (!terms_accepted?)
|
86
|
+
json_error "You must accept the terms of service!", file.original_filename
|
96
87
|
else
|
97
|
-
|
98
|
-
@generic_file = ::GenericFile.new
|
99
|
-
# Relative path is set by the jquery uploader when uploading a directory
|
100
|
-
@generic_file.relative_path = params[:relative_path] if params[:relative_path]
|
101
|
-
Sufia::GenericFile::Actions.create_metadata(@generic_file, current_user, params[:batch_id])
|
102
|
-
Sufia::GenericFile::Actions.create_content(@generic_file, file, file.original_filename, datastream_id, current_user)
|
103
|
-
respond_to do |format|
|
104
|
-
format.html {
|
105
|
-
retval = render :json => [@generic_file.to_jq_upload].to_json,
|
106
|
-
:content_type => 'text/html',
|
107
|
-
:layout => false
|
108
|
-
}
|
109
|
-
format.json {
|
110
|
-
retval = render :json => [@generic_file.to_jq_upload].to_json
|
111
|
-
}
|
112
|
-
end
|
113
|
-
else
|
114
|
-
retval = render :json => [{:error => "Error creating generic file."}].to_json
|
115
|
-
end
|
88
|
+
process_file(file)
|
116
89
|
end
|
117
90
|
rescue => error
|
118
91
|
logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error.to_s}\n #{error.backtrace.join("\n")}\n\n"
|
119
|
-
|
92
|
+
json_error "Error occurred while creating generic file."
|
120
93
|
ensure
|
121
94
|
# remove the tempfile (only if it is a temp file)
|
122
95
|
file.tempfile.delete if file.respond_to?(:tempfile)
|
123
96
|
end
|
124
|
-
|
125
|
-
return retval
|
126
97
|
end
|
127
98
|
|
128
99
|
# routed to /files/:id/citation
|
@@ -131,11 +102,10 @@ module Sufia
|
|
131
102
|
|
132
103
|
# routed to /files/:id
|
133
104
|
def show
|
134
|
-
@can_edit = can? :edit, @generic_file
|
135
|
-
@events = @generic_file.events(100)
|
136
|
-
|
137
105
|
respond_to do |format|
|
138
|
-
format.html
|
106
|
+
format.html {
|
107
|
+
@events = @generic_file.events(100)
|
108
|
+
}
|
139
109
|
format.endnote { render :text => @generic_file.export_as_endnote }
|
140
110
|
end
|
141
111
|
end
|
@@ -164,7 +134,12 @@ module Sufia
|
|
164
134
|
Sufia.queue.push(ContentNewVersionEventJob.new(@generic_file.pid, current_user.user_key))
|
165
135
|
end
|
166
136
|
|
167
|
-
|
137
|
+
# only update metadata if there is a generic_file object which is not the case for version updates
|
138
|
+
update_metadata if params[:generic_file]
|
139
|
+
|
140
|
+
#always save the file so the new version or metadata gets recorded
|
141
|
+
@generic_file.save!
|
142
|
+
|
168
143
|
|
169
144
|
# do not trigger an update event if a version event has already been triggered
|
170
145
|
Sufia.queue.push(ContentUpdateEventJob.new(@generic_file.pid, current_user.user_key)) unless version_event
|
@@ -175,6 +150,51 @@ module Sufia
|
|
175
150
|
|
176
151
|
protected
|
177
152
|
|
153
|
+
def json_error(error, name=nil, additional_arguments={})
|
154
|
+
args = {:error => error}
|
155
|
+
args[:name] = name if name
|
156
|
+
render additional_arguments.merge({:json => [args]})
|
157
|
+
end
|
158
|
+
|
159
|
+
def empty_file?(file)
|
160
|
+
(file.respond_to?(:tempfile) && file.tempfile.size == 0) || (file.respond_to?(:size) && file.size == 0)
|
161
|
+
end
|
162
|
+
|
163
|
+
def process_file(file)
|
164
|
+
if virus_check(file) == 0
|
165
|
+
@generic_file = ::GenericFile.new
|
166
|
+
# Relative path is set by the jquery uploader when uploading a directory
|
167
|
+
@generic_file.relative_path = params[:relative_path] if params[:relative_path]
|
168
|
+
Sufia::GenericFile::Actions.create_metadata(@generic_file, current_user, params[:batch_id])
|
169
|
+
Sufia::GenericFile::Actions.create_content(@generic_file, file, file.original_filename, datastream_id, current_user)
|
170
|
+
respond_to do |format|
|
171
|
+
format.html {
|
172
|
+
render :json => [@generic_file.to_jq_upload],
|
173
|
+
:content_type => 'text/html',
|
174
|
+
:layout => false
|
175
|
+
}
|
176
|
+
format.json {
|
177
|
+
render :json => [@generic_file.to_jq_upload]
|
178
|
+
}
|
179
|
+
end
|
180
|
+
else
|
181
|
+
render :json => [{:error => "Error creating generic file."}]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# override this method if you want to change how the terms are accepted on upload.
|
186
|
+
def terms_accepted?
|
187
|
+
params[:terms_of_service] == '1'
|
188
|
+
end
|
189
|
+
|
190
|
+
# override this method if you need to initialize more complex RDF assertions (b-nodes)
|
191
|
+
def initialize_fields(file)
|
192
|
+
file.terms_for_editing.each do |key|
|
193
|
+
# if value is empty, we create an one element array to loop over for output
|
194
|
+
file[key] = [''] if file[key].empty?
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
178
198
|
# The name of the datastream where we store the file data
|
179
199
|
def datastream_id
|
180
200
|
'content'
|
@@ -186,7 +206,6 @@ module Sufia
|
|
186
206
|
@generic_file.attributes = valid_attributes
|
187
207
|
@generic_file.set_visibility(params[:visibility])
|
188
208
|
@generic_file.date_modified = DateTime.now
|
189
|
-
@generic_file.save!
|
190
209
|
end
|
191
210
|
|
192
211
|
|