Module: Sufia::GenericFile
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern
- Includes:
- Audit, Characterization, Derivatives, Export, Metadata, MimeTypes, Permissions, ReloadOnSave, Thumbnail, Trophies, Versions, VirusCheck, WebForm, ModelMethods, Noid
- Included in:
- GenericFile
- Defined in:
- lib/sufia/models/generic_file.rb,
lib/sufia/models/generic_file/audit.rb,
lib/sufia/models/generic_file/export.rb,
lib/sufia/models/generic_file/actions.rb,
lib/sufia/models/generic_file/metadata.rb,
lib/sufia/models/generic_file/trophies.rb,
lib/sufia/models/generic_file/versions.rb,
lib/sufia/models/generic_file/web_form.rb,
lib/sufia/models/generic_file/thumbnail.rb,
lib/sufia/models/generic_file/mime_types.rb,
lib/sufia/models/generic_file/derivatives.rb,
lib/sufia/models/generic_file/permissions.rb,
lib/sufia/models/generic_file/virus_check.rb,
lib/sufia/models/generic_file/reload_on_save.rb,
lib/sufia/models/generic_file/characterization.rb,
lib/sufia/models/generic_file/accessible_attributes.rb
Defined Under Namespace
Modules: AccessibleAttributes, Actions, Audit, Characterization, Derivatives, Export, Metadata, MimeTypes, Permissions, ReloadOnSave, Thumbnail, Trophies, Versions, VirusCheck, WebForm
Constant Summary
Constants included from Audit
Instance Attribute Summary
Attributes included from ReloadOnSave
Class Method Summary collapse
-
.noid_indexer ⇒ Object
Unstemmed, searchable, stored.
Instance Method Summary collapse
- #label=(new_label) ⇒ Object
- #persistent_url ⇒ Object
-
#processing? ⇒ Boolean
Is this file in the middle of being processed by a batch?.
-
#related_files ⇒ Object
Get the files with a sibling relationship (belongs_to :batch) The batch id is minted when visiting the upload screen and attached to each file when it is done uploading.
- #retry_warming ⇒ Object
-
#to_param ⇒ Object
Redefine this for more intuitive keys in Redis.
- #to_solr(solr_doc = {}, opts = {}) ⇒ Object
Methods included from ReloadOnSave
Methods included from VirusCheck
Methods included from Versions
Methods included from Trophies
Methods included from WebForm
#initialize_fields, #remove_blank_assertions, #terms_for_display, #terms_for_editing, #to_jq_upload
Methods included from AccessibleAttributes
#accessible_attributes, #sanitize_attributes
Methods included from Permissions
#paranoid_permissions, #permissions, #permissions=
Methods included from Audit
#audit, #audit!, #audit_stat, #audit_stat!, #logs, #per_version
Methods included from Characterization
#append_metadata, #characterization_terms, #characterize, #characterize_if_changed, #duration, #height, #sample_rate, #width
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
Methods included from MimeTypes
#audio?, #file_format, #image?, #pdf?, #video?
Methods included from Noid
namespaceize, #noid, noidify, #normalize_identifier
Methods included from ModelMethods
#apply_depositor_metadata, #to_s
Class Method Details
.noid_indexer ⇒ Object
Unstemmed, searchable, stored
94 95 96 |
# File 'lib/sufia/models/generic_file.rb', line 94 def self.noid_indexer @noid_indexer ||= Solrizer::Descriptor.new(:text, :indexed, :stored) end |
Instance Method Details
#label=(new_label) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/sufia/models/generic_file.rb', line 112 def label=(new_label) @inner_object.label = new_label if self.title.empty? self.title = new_label end end |
#persistent_url ⇒ Object
39 40 41 |
# File 'lib/sufia/models/generic_file.rb', line 39 def persistent_url "#{Sufia.config.persistent_hostpath}#{noid}" end |
#processing? ⇒ Boolean
Is this file in the middle of being processed by a batch?
120 121 122 123 124 |
# File 'lib/sufia/models/generic_file.rb', line 120 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 |
#related_files ⇒ Object
Get the files with a sibling relationship (belongs_to :batch) The batch id is minted when visiting the upload screen and attached to each file when it is done uploading. The Batch object is not created until all objects are done uploading and the user is redirected to BatchController#edit. Therefore, we must handle the case where self.batch_id is set but self.batch returns nil. This can get a major overhaul with ActiveFedora 7
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sufia/models/generic_file.rb', line 81 def = begin self.batch.generic_files rescue NoMethodError => e #batch is nil - When would this ever happen? batch_id = self.object_relations["isPartOf"].first || self.object_relations[:is_part_of].first return [] if batch_id.nil? self.class.find(Solrizer.solr_name('is_part_of', :symbol) => batch_id) end .reject { |gf| gf.pid == self.pid } end |
#retry_warming ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sufia/models/generic_file.rb', line 43 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}" # fail for good if the tries is greater than 3 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_param ⇒ Object
Redefine this for more intuitive keys in Redis
108 109 110 |
# File 'lib/sufia/models/generic_file.rb', line 108 def to_param noid end |
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/sufia/models/generic_file.rb', line 98 def to_solr(solr_doc={}, opts={}) super(solr_doc, opts) solr_doc[Solrizer.solr_name('label')] = self.label solr_doc[Solrizer.solr_name('noid', Sufia::GenericFile.noid_indexer)] = noid solr_doc[Solrizer.solr_name('file_format')] = file_format solr_doc[Solrizer.solr_name('file_format', :facetable)] = file_format return solr_doc end |