Module: Sufia::GenericFile
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern
- Includes:
- Audit, Characterization, Derivatives, Export, Metadata, MimeTypes, Permissions, 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/characterization.rb,
lib/sufia/models/generic_file/accessible_attributes.rb
Defined Under Namespace
Modules: AccessibleAttributes, Actions, Audit, Characterization, Derivatives, Export, Metadata, MimeTypes, Permissions, Thumbnail, Trophies, Versions, VirusCheck, WebForm
Constant Summary
Constants included from Audit
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 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
92 93 94 |
# File 'lib/sufia/models/generic_file.rb', line 92 def self.noid_indexer @noid_indexer ||= Solrizer::Descriptor.new(:text, :indexed, :stored) end |
Instance Method Details
#label=(new_label) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/sufia/models/generic_file.rb', line 110 def label=(new_label) @inner_object.label = new_label if self.title.empty? self.title = new_label end end |
#persistent_url ⇒ Object
37 38 39 |
# File 'lib/sufia/models/generic_file.rb', line 37 def persistent_url "#{Sufia.config.persistent_hostpath}#{noid}" end |
#processing? ⇒ Boolean
Is this file in the middle of being processed by a batch?
118 119 120 121 122 |
# File 'lib/sufia/models/generic_file.rb', line 118 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
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sufia/models/generic_file.rb', line 79 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
41 42 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 |
# File 'lib/sufia/models/generic_file.rb', line 41 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
106 107 108 |
# File 'lib/sufia/models/generic_file.rb', line 106 def to_param noid end |
#to_solr(solr_doc = {}, opts = {}) ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/sufia/models/generic_file.rb', line 96 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 |