Class: Asset

Inherits:
Kithe::Asset
  • Object
show all
Includes:
AttrJson::Record::QueryScopes
Defined in:
app/models/asset.rb

Constant Summary collapse

DERIVATIVE_STORAGE_TYPE_LOCATIONS =
{
  "public" => :kithe_derivatives
}.freeze

Instance Method Summary collapse

Instance Method Details

#full_file_urlObject



24
25
26
27
28
29
30
# File 'app/models/asset.rb', line 24

def full_file_url
  if Rails.env.development?
    "http://localhost:3000" + file.url
  else
    file.url
  end
end

#reindex_parentObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/asset.rb', line 49

def reindex_parent
  # Set the "file size" on the parent document
  file_size = 0
  if parent.present? && !parent.destroyed?
    unless thumbnail?
      parent.document_assets.each do |document_asset|
        file_size += document_asset.file_data["metadata"]["size"]
      end
      parent.gbl_fileSize_s = ApplicationController.helpers.number_to_human_size(file_size)
      parent.save(validate: false)
    end
  end
end

#remove_parent_dct_references_uriObject



42
43
44
# File 'app/models/asset.rb', line 42

def remove_parent_dct_references_uri
  GeoblacklightAdmin::RemoveParentDctReferencesUriJob.perform_later(self) if parent_id.present?
end

#set_parent_dct_references_uriObject



35
36
37
# File 'app/models/asset.rb', line 35

def set_parent_dct_references_uri
  GeoblacklightAdmin::SetParentDctReferencesUriJob.perform_later(self) if parent_id.present?
end

#to_aardvark_referenceObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/asset.rb', line 63

def to_aardvark_reference
  hash = {}
  if dct_references_uri_key.present?
    reference_type = ReferenceType.find_by_name(dct_references_uri_key)
    hash[reference_type.reference_uri.to_s] = if reference_type.reference_uri.to_s == "http://schema.org/downloadUrl"
      logger.debug("Asset#to_aardvark_reference > downloadUrl: #{full_file_url} > #{label.present? ? label : file.metadata["filename"]}")

      {
        "url" => full_file_url,
        "label" => label.present? ? label : file.["filename"]
      }
    else
      full_file_url
    end
  end
  hash
end