Class: TeamsiteDigitalAssetShim
- Inherits:
-
Object
- Object
- TeamsiteDigitalAssetShim
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/teamsite_digital_asset_shim.rb
Overview
shim class to allow old teamsite parser to create DigitalAssets in the new format
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(opts = {}) ⇒ Object
- #audience ⇒ Object
- #content_org ⇒ Object
- #content_type ⇒ Object
- #content_type_id ⇒ Object
- #content_type_ids ⇒ Object (also: #doctype_ids)
- #doc_changed_at(path) ⇒ Object
- #doc_size ⇒ Object
- #expired? ⇒ Boolean
- #finra_document ⇒ Object
- #fund_code ⇒ Object
- #has_finra? ⇒ Boolean
- #is_institutional_use? ⇒ Boolean (also: #institutional_use?)
- #is_investor_approved? ⇒ Boolean (also: #investor_approved?)
- #latest_doc_changed_at ⇒ Object
- #pages ⇒ Object
- #path_is(path) ⇒ Object
- #primary_extension ⇒ Object
- #primary_path ⇒ Object
- #product ⇒ Object
- #program ⇒ Object
- #update_attributes!(atts = {}) ⇒ Object
- #validate_future_expiration ⇒ Object
Class Method Details
.bulk_processed? ⇒ Boolean
141 142 143 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 141 def self.bulk_processed? (stale.count.to_f / self.count) <= 0.05 end |
.find_or_initialize_by(attrs = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 72 def self.find_or_initialize_by(attrs = {}) tda = nil # get the base DA if it exists da = DigitalAsset.find_or_initialize_by(attrs) # if it exists copy over the attributes if(da.updated_at.present?) tda = TeamsiteDigitalAssetShim.new(da.attributes) else tda = TeamsiteDigitalAssetShim.new(attrs) end # move metadata from the new spots to the old spots tda.documents.build(path: da.path, doc_changed_at: da.doc_changed_at, content_type: da.content_type, pages: da.pages, size: da.size, mime_type: da.mime_type, subject: da.subject, keywords: da.keywords, author: da.) # make a finra if there is one if(da.finra_path.present?) tda.documents.build(content_type: DigitalAsset::ContentType::FINRA, path: da.finra_path) end tda end |
.purge! ⇒ Object
123 124 125 126 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 123 def self.purge! # last_update = DigitalAsset.desc(:updated_at).try(:first).try :updated_at DigitalAsset.stale.destroy_all if bulk_processed? end |
Instance Method Details
#as_json(opts = {}) ⇒ Object
119 120 121 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 119 def as_json(opts = {}) super(opts).merge({:comp_fundcode => fund_code, :content_type_id => content_type_id, :latest_doc_changed_at => latest_doc_changed_at}) end |
#audience ⇒ Object
213 214 215 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 213 def audience TaxonomyTerm.label_for_term(audiences[0]) end |
#content_org ⇒ Object
195 196 197 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 195 def content_org TaxonomyTerm.label_for_term(content_organization_ids[0]) end |
#content_type ⇒ Object
204 205 206 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 204 def content_type TaxonomyTerm.label_for_term(content_type_id) end |
#content_type_id ⇒ Object
207 208 209 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 207 def content_type_id first_non_finra.try(:content_type) end |
#content_type_ids ⇒ Object Also known as: doctype_ids
157 158 159 160 161 162 163 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 157 def content_type_ids ids = [] documents.try(:each) do |d| ids << d.content_type end ids end |
#doc_changed_at(path) ⇒ Object
149 150 151 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 149 def doc_changed_at(path) path_is(path).try(:doc_changed_at) end |
#doc_size ⇒ Object
153 154 155 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 153 def doc_size first_non_finra.try(:size) end |
#expired? ⇒ Boolean
170 171 172 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 170 def expired? expires_at < Time.now end |
#finra_document ⇒ Object
174 175 176 177 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 174 def finra_document finra_idx = documents.index {|d| d.content_type == DigitalAsset::ContentType::FINRA} documents[finra_idx] if finra_idx end |
#fund_code ⇒ Object
199 200 201 202 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 199 def fund_code pid = product_ids.find {|pid| TaxonomyTerm.term_id_is(pid)[0].try(:fund_code)} pid and TaxonomyTerm.term_id_is(pid)[0].try(:fund_code).try(:rjust, 5, '0') end |
#has_finra? ⇒ Boolean
166 167 168 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 166 def has_finra? finra_document != nil end |
#is_institutional_use? ⇒ Boolean Also known as: institutional_use?
184 185 186 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 184 def is_institutional_use? audiences.index(DigitalAsset::Audience::INSTITUTIONAL_USE) end |
#is_investor_approved? ⇒ Boolean Also known as: investor_approved?
179 180 181 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 179 def is_investor_approved? audiences.index(DigitalAsset::Audience::INVESTOR_APPROVED) end |
#latest_doc_changed_at ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 128 def latest_doc_changed_at documents.reduce(nil) do |latest_date, d| unless d.content_type == '549' latest_date = d.doc_changed_at if (latest_date == nil || latest_date < d.doc_changed_at) end latest_date end end |
#pages ⇒ Object
211 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 211 def pages; first_non_finra.pages end |
#path_is(path) ⇒ Object
145 146 147 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 145 def path_is(path) documents.where(path: path).first unless documents.blank? end |
#primary_extension ⇒ Object
221 222 223 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 221 def primary_extension first_non_finra.try(:path).try(:split,'.').try(:last).try(:upcase) end |
#primary_path ⇒ Object
217 218 219 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 217 def primary_path first_non_finra.try(:path) end |
#product ⇒ Object
189 190 191 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 189 def product TaxonomyTerm.label_for_term(product_ids[0]) end |
#program ⇒ Object
192 193 194 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 192 def program TaxonomyTerm.label_for_term(program_ids[0]) end |
#update_attributes!(atts = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 93 def update_attributes!(atts = {}) # deconvert metadata from old to new self.attributes = atts atts.delete('documents_attributes') da = DigitalAsset.new(atts) doc = first_non_finra da.path = doc.try(:path) da.finra_path = finra_document.try(:path) da.doc_changed_at = doc.doc_changed_at da.content_type = doc.content_type da.pages = doc.pages da.size = doc.size da.mime_type = doc.mime_type da.subject = doc.subject da.keywords = doc.keywords da. = doc. da.digital_asset_id = guid # try to find fund-codes # codes = product_ids.try(:collect) do |id| # TaxonomyTerm.term_id_is(id).try(:first).try(:term_type).try([], 'FUND_CODE') # end.try(:compact) # save the new metadata format da.save! end |
#validate_future_expiration ⇒ Object
137 138 139 |
# File 'app/models/teamsite_digital_asset_shim.rb', line 137 def validate_future_expiration errors.add(:expires_at, "Expiration date must be at least 1 minute from now") unless expires_at and expires_at > 1.minute.from_now end |