sufia-models 0.1.2 → 2.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/app/models/datastreams/generic_file_rdf_datastream.rb +12 -12
- data/app/models/datastreams/paranoid_rights_datastream.rb +0 -15
- data/app/models/datastreams/properties_datastream.rb +1 -2
- data/lib/sufia/models/engine.rb +15 -0
- data/lib/sufia/models/generic_file/actions.rb +12 -0
- data/lib/sufia/models/generic_file/web_form.rb +30 -0
- data/lib/sufia/models/generic_file.rb +1 -28
- data/lib/sufia/models/id_service.rb +1 -1
- data/lib/sufia/models/jobs/import_url_job.rb +55 -0
- data/lib/sufia/models/jobs/unzip_job.rb +16 -4
- data/lib/sufia/models/version.rb +1 -1
- data/lib/sufia/models.rb +0 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ef0788884e77751228fd4729bf0d364cf4b7eb7
|
4
|
+
data.tar.gz: 6a068dfdb18c10b6e1c6fa1bec8bb08b8d112fd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05a7f5da307b2f79017c726fb9cda5ac5278935635537d732c3c5bb5a1f2238d213236a99ae840dfd69418ab072e3f69f14d539c5d64a5b478a9614de98b02d
|
7
|
+
data.tar.gz: fc46b8587afa6b5c5e75675e90cfcb80aa28fef6e3efbe5ecafec98d68fee3b883e71848b12e56352257371a15c75bf84d3086f5090d4ba6f25a3253c6945b9d
|
@@ -15,19 +15,28 @@
|
|
15
15
|
class GenericFileRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
16
16
|
map_predicates do |map|
|
17
17
|
map.part_of(:to => "isPartOf", :in => RDF::DC)
|
18
|
-
map.
|
18
|
+
map.resource_type(:to => "type", :in => RDF::DC) do |index|
|
19
19
|
index.as :stored_searchable, :facetable
|
20
20
|
end
|
21
|
+
map.title(:in => RDF::DC) do |index|
|
22
|
+
index.as :stored_searchable
|
23
|
+
end
|
21
24
|
map.creator(:in => RDF::DC) do |index|
|
22
25
|
index.as :stored_searchable, :facetable
|
23
26
|
end
|
24
|
-
map.
|
25
|
-
index.as :stored_searchable
|
27
|
+
map.contributor(:in => RDF::DC) do |index|
|
28
|
+
index.as :stored_searchable, :facetable
|
26
29
|
end
|
27
30
|
map.description(:in => RDF::DC) do |index|
|
28
31
|
index.type :text
|
29
32
|
index.as :stored_searchable
|
30
33
|
end
|
34
|
+
map.tag(:to => "relation", :in => RDF::DC) do |index|
|
35
|
+
index.as :stored_searchable, :facetable
|
36
|
+
end
|
37
|
+
map.rights(:in => RDF::DC) do |index|
|
38
|
+
index.as :stored_searchable
|
39
|
+
end
|
31
40
|
map.publisher(:in => RDF::DC) do |index|
|
32
41
|
index.as :stored_searchable, :facetable
|
33
42
|
end
|
@@ -48,21 +57,12 @@ class GenericFileRdfDatastream < ActiveFedora::NtriplesRDFDatastream
|
|
48
57
|
map.language(:in => RDF::DC) do |index|
|
49
58
|
index.as :stored_searchable, :facetable
|
50
59
|
end
|
51
|
-
map.rights(:in => RDF::DC) do |index|
|
52
|
-
index.as :stored_searchable
|
53
|
-
end
|
54
|
-
map.resource_type(:to => "type", :in => RDF::DC) do |index|
|
55
|
-
index.as :stored_searchable, :facetable
|
56
|
-
end
|
57
60
|
map.identifier(:in => RDF::DC) do |index|
|
58
61
|
index.as :stored_searchable
|
59
62
|
end
|
60
63
|
map.based_near(:in => RDF::FOAF) do |index|
|
61
64
|
index.as :stored_searchable, :facetable
|
62
65
|
end
|
63
|
-
map.tag(:to => "relation", :in => RDF::DC) do |index|
|
64
|
-
index.as :stored_searchable, :facetable
|
65
|
-
end
|
66
66
|
map.related_url(:to => "seeAlso", :in => RDF::RDFS)
|
67
67
|
end
|
68
68
|
begin
|
@@ -1,18 +1,3 @@
|
|
1
|
-
# Copyright © 2012 The Pennsylvania State University
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
|
15
|
-
require 'hydra/datastream/rights_metadata'
|
16
1
|
# subclass built-in Hydra RightsDatastream and build in extra model-level validation
|
17
2
|
class ParanoidRightsDatastream < Hydra::Datastream::RightsMetadata
|
18
3
|
use_terminology Hydra::Datastream::RightsMetadata
|
@@ -20,8 +20,7 @@ class PropertiesDatastream < ActiveFedora::OmDatastream
|
|
20
20
|
t.depositor :index_as=>[:stored_searchable]
|
21
21
|
# This is where we put the relative path of the file if submitted as a folder
|
22
22
|
t.relative_path
|
23
|
-
|
24
|
-
t.proxy_depositor path: 'proxyDepositor', :index_as=>:symbol
|
23
|
+
t.import_url path: 'importUrl', :index_as=>:symbol
|
25
24
|
end
|
26
25
|
|
27
26
|
def self.xml_template
|
data/lib/sufia/models/engine.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'sufia/models/resque'
|
1
2
|
module Sufia
|
2
3
|
module Models
|
3
4
|
def self.config(&block)
|
@@ -9,6 +10,20 @@ module Sufia
|
|
9
10
|
end
|
10
11
|
|
11
12
|
class Engine < ::Rails::Engine
|
13
|
+
|
14
|
+
# Set some configuration defaults
|
15
|
+
config.enable_ffmpeg = false
|
16
|
+
config.noid_template = '.reeddeeddk'
|
17
|
+
config.ffmpeg_path = 'ffmpeg'
|
18
|
+
config.fits_message_length = 5
|
19
|
+
config.temp_file_base = nil
|
20
|
+
config.minter_statefile = '/tmp/minter-state'
|
21
|
+
config.id_namespace = "sufia"
|
22
|
+
config.fits_path = "fits.sh"
|
23
|
+
config.enable_contact_form_delivery = false
|
24
|
+
config.dropbox_api_key = nil
|
25
|
+
config.queue = Sufia::Resque::Queue
|
26
|
+
|
12
27
|
config.autoload_paths += %W(
|
13
28
|
#{config.root}/lib/sufia/models/jobs
|
14
29
|
#{config.root}/app/models/datastreams
|
@@ -38,5 +38,17 @@ module Sufia::GenericFile
|
|
38
38
|
Sufia.config.after_create_content.call(generic_file, user)
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
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
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
41
53
|
end
|
42
54
|
end
|
@@ -1,6 +1,16 @@
|
|
1
1
|
module Sufia
|
2
2
|
module GenericFile
|
3
3
|
module WebForm
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
included do
|
6
|
+
before_save :remove_blank_assertions
|
7
|
+
end
|
8
|
+
|
9
|
+
def remove_blank_assertions
|
10
|
+
terms_for_editing.each do |key|
|
11
|
+
self[key] = nil if self[key] == ['']
|
12
|
+
end
|
13
|
+
end
|
4
14
|
|
5
15
|
# override this method if you need to initialize more complex RDF assertions (b-nodes)
|
6
16
|
def initialize_fields
|
@@ -10,6 +20,26 @@ module Sufia
|
|
10
20
|
end
|
11
21
|
end
|
12
22
|
|
23
|
+
def terms_for_editing
|
24
|
+
terms_for_display -
|
25
|
+
[:part_of, :date_modified, :date_uploaded, :format] #, :resource_type]
|
26
|
+
end
|
27
|
+
|
28
|
+
def terms_for_display
|
29
|
+
self.descMetadata.class.config.keys
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_jq_upload
|
33
|
+
return {
|
34
|
+
"name" => self.title,
|
35
|
+
"size" => self.file_size,
|
36
|
+
"url" => "/files/#{noid}",
|
37
|
+
"thumbnail_url" => self.pid,
|
38
|
+
"delete_url" => "deleteme", # generic_file_path(:id => id),
|
39
|
+
"delete_type" => "DELETE"
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
13
43
|
end
|
14
44
|
end
|
15
45
|
end
|
@@ -26,7 +26,7 @@ module Sufia
|
|
26
26
|
|
27
27
|
belongs_to :batch, :property => :is_part_of
|
28
28
|
|
29
|
-
delegate_to :properties, [:relative_path, :depositor], :unique => true
|
29
|
+
delegate_to :properties, [:relative_path, :depositor, :import_url], :unique => true
|
30
30
|
delegate_to :descMetadata, [:date_uploaded, :date_modified], :unique => true
|
31
31
|
delegate_to :descMetadata, [:related_url, :based_near, :part_of, :creator,
|
32
32
|
:contributor, :title, :tag, :description, :rights,
|
@@ -34,16 +34,9 @@ module Sufia
|
|
34
34
|
:resource_type, :identifier, :language]
|
35
35
|
|
36
36
|
around_save :characterize_if_changed, :retry_warming
|
37
|
-
before_save :remove_blank_assertions
|
38
37
|
before_destroy :cleanup_trophies
|
39
38
|
end
|
40
39
|
|
41
|
-
def remove_blank_assertions
|
42
|
-
terms_for_editing.each do |key|
|
43
|
-
self[key] = nil if self[key] == ['']
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
40
|
|
48
41
|
def record_version_committer(user)
|
49
42
|
version = content.latest_version
|
@@ -157,26 +150,6 @@ module Sufia
|
|
157
150
|
end
|
158
151
|
end
|
159
152
|
|
160
|
-
def to_jq_upload
|
161
|
-
return {
|
162
|
-
"name" => self.title,
|
163
|
-
"size" => self.file_size,
|
164
|
-
"url" => "/files/#{noid}",
|
165
|
-
"thumbnail_url" => self.pid,
|
166
|
-
"delete_url" => "deleteme", # generic_file_path(:id => id),
|
167
|
-
"delete_type" => "DELETE"
|
168
|
-
}
|
169
|
-
end
|
170
|
-
|
171
|
-
def terms_for_editing
|
172
|
-
terms_for_display -
|
173
|
-
[:part_of, :date_modified, :date_uploaded, :format] #, :resource_type]
|
174
|
-
end
|
175
|
-
|
176
|
-
def terms_for_display
|
177
|
-
self.descMetadata.class.config.keys
|
178
|
-
end
|
179
|
-
|
180
153
|
# Is this file in the middle of being processed by a batch?
|
181
154
|
def processing?
|
182
155
|
return false if self.batch.blank?
|
@@ -43,7 +43,7 @@ module Sufia
|
|
43
43
|
|
44
44
|
def self.next_id
|
45
45
|
pid = ''
|
46
|
-
File.open(Sufia
|
46
|
+
File.open(Sufia.config.minter_statefile, File::RDWR|File::CREAT, 0644) do |f|
|
47
47
|
f.flock(File::LOCK_EX)
|
48
48
|
yaml = YAML::load(f.read)
|
49
49
|
yaml = {:template => noid_template} unless yaml
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
class ImportUrlJob
|
6
|
+
|
7
|
+
def queue_name
|
8
|
+
:import_url
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :pid
|
12
|
+
|
13
|
+
def initialize(pid)
|
14
|
+
self.pid = pid
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
generic_file = GenericFile.find(self.pid)
|
19
|
+
f = Tempfile.new(self.pid)
|
20
|
+
f.binmode
|
21
|
+
|
22
|
+
# download file from url
|
23
|
+
uri = URI(generic_file.import_url)
|
24
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
25
|
+
http.use_ssl = uri.scheme == "https" # enable SSL/TLS
|
26
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
27
|
+
|
28
|
+
http.start do
|
29
|
+
http.request_get(uri) do |resp|
|
30
|
+
resp.read_body do |segment|
|
31
|
+
f.write(segment)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
job_user = User.batchuser()
|
36
|
+
user = User.find_by_user_key(generic_file.depositor)
|
37
|
+
# check for virus
|
38
|
+
if Sufia::GenericFile::Actions.virus_check(f) != 0
|
39
|
+
message = "The file (#{File.basename(uri.path)}) was unable to be imported because it contained a virus."
|
40
|
+
job_user.send_message(user, message, 'File Import Error')
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
f.rewind
|
45
|
+
# attach downloaded file to generic file stubbed out
|
46
|
+
Sufia::GenericFile::Actions.create_content(generic_file, f, File.basename(uri.path), 'content', user)
|
47
|
+
# add message to user for downloaded file
|
48
|
+
message = "The file (#{File.basename(uri.path)}) was successfully imported."
|
49
|
+
job_user.send_message(user, message, 'File Import')
|
50
|
+
|
51
|
+
ensure
|
52
|
+
f.close
|
53
|
+
f.unlink
|
54
|
+
end
|
55
|
+
end
|
@@ -26,27 +26,39 @@ class UnzipJob
|
|
26
26
|
def run
|
27
27
|
Zip::Archive.open_buffer(zip_file.content.content) do |archive|
|
28
28
|
archive.each do |f|
|
29
|
-
|
29
|
+
if f.directory?
|
30
|
+
create_directory(f)
|
31
|
+
else
|
32
|
+
create_file(f)
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
34
38
|
protected
|
35
39
|
|
36
|
-
|
40
|
+
# Creates a GenericFile object based on +file+
|
41
|
+
# @param file [Zip::File]
|
42
|
+
def create_file(file)
|
37
43
|
@generic_file = GenericFile.new
|
38
44
|
@generic_file.batch_id = zip_file.batch.pid
|
39
|
-
file_name =
|
45
|
+
file_name = file.name
|
40
46
|
mime_types = MIME::Types.of(file_name)
|
41
47
|
mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
|
42
48
|
options = {:label=>file_name, :dsid=>'content', :mimeType=>mime_type}
|
43
|
-
@generic_file.add_file_datastream(
|
49
|
+
@generic_file.add_file_datastream(file.read, options)
|
44
50
|
@generic_file.set_title_and_label( file_name, :only_if_blank=>true )
|
45
51
|
@generic_file.apply_depositor_metadata(zip_file.edit_users.first)
|
46
52
|
@generic_file.date_uploaded = Time.now.ctime
|
47
53
|
@generic_file.date_modified = Time.now.ctime
|
48
54
|
@generic_file.save
|
49
55
|
end
|
56
|
+
|
57
|
+
# Creates representation of directory corresponding to +file+
|
58
|
+
# Default behavior: _do nothing_
|
59
|
+
# @param file [Zip::File]
|
60
|
+
def create_directory(file)
|
61
|
+
end
|
50
62
|
|
51
63
|
def zip_file
|
52
64
|
@zip_file ||= GenericFile.find(pid)
|
data/lib/sufia/models/version.rb
CHANGED
data/lib/sufia/models.rb
CHANGED
@@ -14,14 +14,8 @@ module Sufia
|
|
14
14
|
extend ActiveSupport::Autoload
|
15
15
|
|
16
16
|
module Models
|
17
|
-
|
18
|
-
extend ActiveSupport::Autoload
|
19
|
-
|
20
|
-
autoload :Resque, 'sufia/models/queue/resque'
|
21
|
-
autoload :User, 'sufia/models/user'
|
22
17
|
end
|
23
18
|
|
24
|
-
autoload :Resque, 'sufia/models/resque'
|
25
19
|
autoload :Utils, 'sufia/models/utils'
|
26
20
|
|
27
21
|
attr_writer :queue
|
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: 0.
|
4
|
+
version: 2.0.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-06-
|
11
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -273,6 +273,7 @@ files:
|
|
273
273
|
- lib/sufia/models/jobs/batch_update_job.rb
|
274
274
|
- lib/sufia/models/jobs/characterize_job.rb
|
275
275
|
- lib/sufia/models/jobs/ffmpeg_transcode_job.rb
|
276
|
+
- lib/sufia/models/jobs/import_url_job.rb
|
276
277
|
- lib/sufia/models/jobs/resolrize_job.rb
|
277
278
|
- lib/sufia/models/jobs/transcode_audio_job.rb
|
278
279
|
- lib/sufia/models/jobs/transcode_video_job.rb
|