Module: Sufia::GenericFile
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern
- Includes:
- Audit, Characterization, Export, Permissions, Thumbnail, ModelMethods, Noid
- Included in:
- GenericFile
- Defined in:
- lib/sufia/generic_file.rb,
lib/sufia/generic_file/audit.rb,
lib/sufia/generic_file/export.rb,
lib/sufia/generic_file/thumbnail.rb,
lib/sufia/generic_file/permissions.rb,
lib/sufia/generic_file/characterization.rb
Defined Under Namespace
Modules: Audit, Characterization, ClassMethods, Export, Permissions, Thumbnail
Constant Summary
Constants included
from Audit
Audit::NO_RUNS
Instance Method Summary
collapse
#paranoid_permissions, #permissions=, #set_visibility
Methods included from Audit
#audit, #audit!, #audit_stat, #audit_stat!, #logs, #per_version
#append_metadata, #characterization_terms, #characterize, #characterize_if_changed
Methods included from Export
#export_as_apa_citation, #export_as_chicago_citation, #export_as_endnote, #export_as_mla_citation, #export_as_openurl_ctx_kev
Methods included from Thumbnail
#create_image_thumbnail, #create_pdf_thumbnail, #create_thumbnail
Methods included from Noid
namespaceize, #noid, noidify, #normalize_identifier
#apply_depositor_metadata
Instance Method Details
116
117
118
119
120
121
|
# File 'lib/sufia/generic_file.rb', line 116
def file_format
return nil if self.mime_type.blank? and self.format_label.blank?
return self.mime_type.split('/')[1]+ " ("+self.format_label.join(", ")+")" unless self.mime_type.blank? or self.format_label.blank?
return self.mime_type.split('/')[1] unless self.mime_type.blank?
return self.format_label
end
|
#get_terms ⇒ Object
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/sufia/generic_file.rb', line 146
def get_terms
terms = []
self.descMetadata.class.config[:predicate_mapping].each do |uri, mappings|
new_terms = mappings.keys.map(&:to_s).select do |term|
term.start_with? "generic_file__" and !['type', 'behaviors'].include? term.split('__').last
end
terms.concat(new_terms)
end
terms
end
|
#get_values ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/sufia/generic_file.rb', line 157
def get_values
terms = get_terms
values = {}
terms.each do |t|
next if t.empty?
key = t.to_s.split("generic_file__").last
next if ['part_of', 'date_modified', 'date_uploaded', 'format'].include?(key)
values[key] = self.send(key) if self.respond_to?(key)
end
return values
end
|
#image? ⇒ Boolean
47
48
49
|
# File 'lib/sufia/generic_file.rb', line 47
def image?
["image/png","image/jpeg", 'image/jpg', 'image/bmp', "image/gif"].include? self.mime_type
end
|
#label=(new_label) ⇒ Object
128
129
130
131
132
133
|
# File 'lib/sufia/generic_file.rb', line 128
def label=(new_label)
@inner_object.label = new_label
if self.title.empty?
self.title = new_label
end
end
|
#pdf? ⇒ Boolean
43
44
45
|
# File 'lib/sufia/generic_file.rb', line 43
def pdf?
["application/pdf"].include? self.mime_type
end
|
#persistent_url ⇒ Object
55
56
57
|
# File 'lib/sufia/generic_file.rb', line 55
def persistent_url
"#{Sufia::Engine.config.persistent_hostpath}#{noid}"
end
|
#processing? ⇒ Boolean
Is this file in the middle of being processed by a batch?
170
171
172
173
174
|
# File 'lib/sufia/generic_file.rb', line 170
def processing?
return false if self.batch.blank?
return false if !self.batch.methods.include? :status
return (!self.batch.status.empty?) && (self.batch.status.count == 1) && (self.batch.status[0] == "processing")
end
|
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/sufia/generic_file.rb', line 91
def related_files
relateds = begin
self.batch.generic_files
rescue NoMethodError => e
batch_id = self.object_relations["isPartOf"].first || self.object_relations[:is_part_of].first
return [] if batch_id.nil?
self.class.find(:is_part_of_s => batch_id)
end
relateds.reject { |gf| gf.pid == self.pid }
end
|
#retry_warming ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/sufia/generic_file.rb', line 59
def retry_warming
save_tries = 0
conflict_tries = 0
begin
yield
rescue RSolr::Error::Http => error
save_tries += 1
logger.warn "Retry Solr caught RSOLR error on #{self.pid}: #{error.inspect}"
raise if save_tries >=3
sleep 0.01
retry
rescue ActiveResource::ResourceConflict => error
conflict_tries += 1
logger.warn "Retry caught Active Resource Conflict #{self.pid}: #{error.inspect}"
raise if conflict_tries >=10
sleep 0.01
retry
rescue =>error
if (error.to_s.downcase.include? "conflict")
conflict_tries += 1
logger.warn "Retry caught Active Resource Conflict #{self.pid}: #{error.inspect}"
raise if conflict_tries >=10
sleep 0.01
retry
else
raise
end
end
end
|
#to_jq_upload ⇒ Object
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/sufia/generic_file.rb', line 135
def to_jq_upload
return {
"name" => self.title,
"size" => self.file_size,
"url" => "/files/#{noid}",
"thumbnail_url" => self.pid,
"delete_url" => "deleteme", "delete_type" => "DELETE"
}
end
|
#to_param ⇒ Object
Redefine this for more intuitive keys in Redis
124
125
126
|
# File 'lib/sufia/generic_file.rb', line 124
def to_param
noid
end
|
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/sufia/generic_file.rb', line 104
def to_solr(solr_doc={}, opts={})
super(solr_doc, opts)
solr_doc["label_t"] = self.label
solr_doc["noid_s"] = noid
solr_doc["file_format_t"] = file_format
solr_doc["file_format_facet"] = solr_doc["file_format_t"]
solr_doc['generic_file__date_uploaded_dt'] = Time.parse(date_uploaded).utc.to_s.sub(' ','T').sub(' UTC','Z') rescue Time.new(date_uploaded).utc.to_s.sub(' ','T').sub(' UTC','Z') unless date_uploaded.blank?
solr_doc['generic_file__date_modified_dt'] = Time.parse(date_modified).utc.to_s.sub(' ','T').sub(' UTC','Z') rescue Time.new(date_modified).utc.to_s.sub(' ','T').sub(' UTC','Z') unless date_modified.blank?
return solr_doc
end
|
#video? ⇒ Boolean
51
52
53
|
# File 'lib/sufia/generic_file.rb', line 51
def video?
["video/mpeg", "video/mp4", "video/x-msvideo", "video/avi", "video/quicktime"].include? self.mime_type
end
|