ontology_version.rb revision acb3db0ee20cd276e305da358a03b30666976db0
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerclass OntologyVersion < ActiveRecord::Base
87107747f8a51d0f07c2e2a415fcf9c494783f0fhenning mueller include OntologyVersion::Async
87107747f8a51d0f07c2e2a415fcf9c494783f0fhenning mueller include OntologyVersion::Download
9c9b4f0d0199c3b1dbff564b87435b6693b7e692Julian Kornberger include OntologyVersion::Parsing
b2dbef8c73faa240d208f3ff9fb49b21d9a894a5Daniel Vale include OntologyVersion::Numbers
7ea9649883e1bbe8f2582db1a3c66af8b7206056henning mueller
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning mueller belongs_to :user
cbb18f95cb8354f0c3fb44ba5134dadc7ad6b2ecJulian Kornberger belongs_to :ontology, :counter_cache => :versions_count
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller mount_uploader :raw_file, OntologyUploader
3cd45197413df1ff1401697720f1ac9ccef8f8eehenning mueller mount_uploader :xml_file, OntologyUploader
ec96c6e3605c2e9eb5c0113e4e1b07b3b5228c8chenning mueller
a14e1ccbd2588441fb5a59e0c82f895b5c42c298Julian Kornberger attr_accessible :raw_file, :source_url
d12cf3a51e30d69a53108694ba68ba584942dbb8henning mueller
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller before_validation :set_checksum
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller
acb3db0ee20cd276e305da358a03b30666976db0Daniel Couto Vale validate :presence_of_raw_file_or_source_url, :on => :create
22e260fcd85642794d99c2ffaa333f2ef6ed7828Daniel Couto Vale# validate :raw_file_size_maximum
ecf32c9d659a1f42c730d61eaa93583c095a4fddhenning mueller
a14e1ccbd2588441fb5a59e0c82f895b5c42c298Julian Kornberger validates_format_of :source_url,
a14e1ccbd2588441fb5a59e0c82f895b5c42c298Julian Kornberger :with => URI::regexp(ALLOWED_URI_SCHEMAS), :if => :source_url?
0772cf7b22adf46dbab68e829d6a2cd8e8d1bc2ahenning mueller
432ee743a5f1c5688c73446b5977b06ed97fb67cJulian Kornberger scope :latest, order('id DESC')
b9f99a06294e593ce8fb34b015e83003229db058Julian Kornberger scope :state, ->(state) { where :state => state }
b9f99a06294e593ce8fb34b015e83003229db058Julian Kornberger scope :done, state('done')
b3b159fb3284b66d0f8189a6a145c8163ccdae68henning mueller scope :failed, state('failed')
7ea9649883e1bbe8f2582db1a3c66af8b7206056henning mueller
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
631f43db46ad7d375010c3169c81764eb27270a3Julian Kornberger
ffddc54fc6bb11130abd3281dcd95159c7f3ce7fJulian Kornberger def source_name
a14e1ccbd2588441fb5a59e0c82f895b5c42c298Julian Kornberger source_url? ? source_url : 'File upload'
ffddc54fc6bb11130abd3281dcd95159c7f3ce7fJulian Kornberger end
ffddc54fc6bb11130abd3281dcd95159c7f3ce7fJulian Kornberger
ae2ba7aeef036808e81fb6449e98ce9abb0fb234Daniel Couto Vale def to_param
7dc318cbd9f8c97406b48051005f23953e9e8a25Daniel Vale self.number
ae2ba7aeef036808e81fb6449e98ce9abb0fb234Daniel Couto Vale end
acb3db0ee20cd276e305da358a03b30666976db0Daniel Couto Vale
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning muellerprotected
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller
acb3db0ee20cd276e305da358a03b30666976db0Daniel Couto Vale def presence_of_raw_file_or_source_url
acb3db0ee20cd276e305da358a03b30666976db0Daniel Couto Vale if raw_file.blank? and source_url.blank?
a14e1ccbd2588441fb5a59e0c82f895b5c42c298Julian Kornberger errors.add :source_url, 'Specify either a source file or URI.'
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller end
8d4d8ac34f199d5c7d26694fabbfe2ab6bc0f9d9henning mueller end
acb3db0ee20cd276e305da358a03b30666976db0Daniel Couto Vale
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
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller def set_checksum
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller self.checksum = raw_file.sha1 if raw_file.present? and raw_file_changed?
1b6021653a43264993b21ebb20e0119aa2fd6741henning mueller end
0075dcb5aeeee4864fe9f64db82c8a8202bbe6d6henning muellerend