ontology_version.rb revision 33d42e7c36aef2d703ed3e35536dca4cd4290470
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerclass OntologyVersion < ActiveRecord::Base
39f4456a75fd3e8b00e5eaa1158086c5cbf0774cTim Reddehase include CodeReferencable
39f4456a75fd3e8b00e5eaa1158086c5cbf0774cTim Reddehase
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger include OntologyVersion::Files
5cad3e82e8c017bc189c4cecc00541ec19a2a6e2Julian Kornberger include OntologyVersion::States
9c9b4f0d0199c3b1dbff564b87435b6693b7e692Julian Kornberger include OntologyVersion::Parsing
b2dbef8c73faa240d208f3ff9fb49b21d9a894a5Daniel Vale include OntologyVersion::Numbers
dda6f544eb58d850394073e34ae6127498869a77Christian Clausen include OntologyVersion::OopsRequests
1926bd12c68c7c499d4251daf6341519193ca8c4Tim Reddehase include IRIUrlBuilder::Includeable
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller include Rails.application.routes.url_helpers
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller include ActionDispatch::Routing::UrlFor
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning mueller belongs_to :user
cbb18f95cb8354f0c3fb44ba5134dadc7ad6b2ecJulian Kornberger belongs_to :ontology, :counter_cache => :versions_count
aca8ebc07736136a816f0a71534730ec65472df3Tim Reddehase belongs_to :commit
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller# before_validation :set_checksum
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller# validate :raw_file_size_maximum
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller
bceeb5195a8524674b37f6abd92ccaba357e536bSascha Graef# validates_presence_of :basepath
0772cf7b22adf46dbab68e829d6a2cd8e8d1bc2ahenning mueller
432ee743a5f1c5688c73446b5977b06ed97fb67cJulian Kornberger scope :latest, order('id DESC')
b9f99a06294e593ce8fb34b015e83003229db058Julian Kornberger scope :done, state('done')
b3b159fb3284b66d0f8189a6a145c8163ccdae68henning mueller scope :failed, state('failed')
7ea9649883e1bbe8f2582db1a3c66af8b7206056henning mueller
a5015ca9daa067f062e9e373c3dfafd5631560d9Julian Kornberger delegate :repository, to: :ontology
a5015ca9daa067f062e9e373c3dfafd5631560d9Julian Kornberger
6c8d349bce5a8aa4c5af757a84d9432153024e8fTim Reddehase acts_as_tree
6c8d349bce5a8aa4c5af757a84d9432153024e8fTim Reddehase
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger # updated_at of the latest version
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger def self.last_updated_at
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger latest.first.try(:updated_at)
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger end
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
ae2ba7aeef036808e81fb6449e98ce9abb0fb234Daniel Couto Vale def to_param
7dc318cbd9f8c97406b48051005f23953e9e8a25Daniel Vale self.number
ae2ba7aeef036808e81fb6449e98ce9abb0fb234Daniel Couto Vale end
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller # Public URL to this version
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller #
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller # TODO: This returns a path without the commit id and filename for now,
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller # because the FilesController or the routes were not supporting it.
43a0f914166a28a9d7f75ab10673dce129cb38a9Julian Kornberger def url(params={})
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller #Rails.application.routes.url_helpers.repository_ref_path(repository, commit_oid, ontology.path, params.reverse_merge(host: Settings.hostname, only_path: false))
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller url_for [repository, ontology, self]
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller end
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller def default_url_options
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller {host: Settings.hostname}
43a0f914166a28a9d7f75ab10673dce129cb38a9Julian Kornberger end
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
823b204d13c129df1ae3b49ff62ee1da0c8f6b63Eugen Kuksa def path
823b204d13c129df1ae3b49ff62ee1da0c8f6b63Eugen Kuksa "#{basepath}#{file_extension}"
823b204d13c129df1ae3b49ff62ee1da0c8f6b63Eugen Kuksa end
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller
2ae84818de6541409f6c8f2b417b868325aed315Tim Reddehase def file_in_repository
36775360692520baa2625045372081b2cbc9959dTim Reddehase ontology.repository.get_file(path, commit_oid)
2ae84818de6541409f6c8f2b417b868325aed315Tim Reddehase end
2ae84818de6541409f6c8f2b417b868325aed315Tim Reddehase
33d42e7c36aef2d703ed3e35536dca4cd4290470Tim Reddehase def locid
33d42e7c36aef2d703ed3e35536dca4cd4290470Tim Reddehase "/ref/#{number}#{ontology.locid}"
33d42e7c36aef2d703ed3e35536dca4cd4290470Tim Reddehase end
33d42e7c36aef2d703ed3e35536dca4cd4290470Tim Reddehase
33d42e7c36aef2d703ed3e35536dca4cd4290470Tim Reddehase alias_method :versioned_locid, :locid
33d42e7c36aef2d703ed3e35536dca4cd4290470Tim Reddehase
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller protected
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller def raw_file_size_maximum
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller if raw_file.size > 10.megabytes.to_i
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller errors.add :raw_file, 'The maximum file size is 10M.'
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller end
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller end
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller
0eae0f423c62bcc939e76f37ce7a7a9913b58422Julian Kornberger def refresh_checksum!
0eae0f423c62bcc939e76f37ce7a7a9913b58422Julian Kornberger self.checksum = Digest::SHA1.file(raw_path!).hexdigest
0eae0f423c62bcc939e76f37ce7a7a9913b58422Julian Kornberger save! if checksum_changed?
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller end
b0ad67a7b41855a9148f346eb5b5d2b9276796ddhenning mueller
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerend