files.rb revision a3923a34a7ada40e7db50fd8e58af228616f62c0
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornbergermodule OntologyVersion::Files
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger extend ActiveSupport::Concern
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger included do
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger # virtual attribute for upload
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger attr_accessible :raw_file
7097237ffbd7227b30272b307b6e48c78b22ecb1Julian Kornberger before_create :commit_raw_file, unless: :commit_oid?
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger end
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger def raw_file=(value)
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger @raw_file = value
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
7097237ffbd7227b30272b307b6e48c78b22ecb1Julian Kornberger def commit_raw_file
89849d4f0871f414f3d7d8e926bb10e9db19fd57Eugen Kuksa return true if ontology.parent
7097237ffbd7227b30272b307b6e48c78b22ecb1Julian Kornberger raise "raw file missing" unless @raw_file
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa ontology.path = @raw_file.original_filename if ontology.path.nil?
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa # otherwise the file upload is broken (no implicit conversion of ActionDispatch::Http::UploadedFile into String):
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa tmp_file = if @raw_file.class == ActionDispatch::Http::UploadedFile
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa @raw_file.tempfile
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa else
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa @raw_file
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa end
24a4fef0ec5817f68ff5dd8bc59c1ce947187fabEugen Kuksa repository.save_file(tmp_file, ontology.path, "message", user)
7097237ffbd7227b30272b307b6e48c78b22ecb1Julian Kornberger end
7097237ffbd7227b30272b307b6e48c78b22ecb1Julian Kornberger
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def tmp_dir
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger Rails.root.join("tmp","commits",commit_oid)
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger # path to the raw file
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def raw_path
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger tmp_dir.join("raw",ontology.path)
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger # path to the raw file, checks out the raw file if is missing
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def raw_path!
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger checkout_raw!
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger raw_path
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger # path to xml file (hets output)
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def xml_path
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger tmp_dir.join("xml", ontology.path)
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
a3923a34a7ada40e7db50fd8e58af228616f62c0Tim Reddehase # path to xml file (hets output) with code positions
a3923a34a7ada40e7db50fd8e58af228616f62c0Tim Reddehase def code_reference_path
a3923a34a7ada40e7db50fd8e58af228616f62c0Tim Reddehase tmp_dir.join("xml",
a3923a34a7ada40e7db50fd8e58af228616f62c0Tim Reddehase ontology.path.sub(ontology.file_extension, '.pp.xml'))
a3923a34a7ada40e7db50fd8e58af228616f62c0Tim Reddehase end
a3923a34a7ada40e7db50fd8e58af228616f62c0Tim Reddehase
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def xml_file?
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger File.exists? xml_path
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def raw_file?
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger File.exists? raw_path
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger # checks out the raw file
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def checkout_raw!
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger unless raw_file?
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger FileUtils.mkdir_p raw_path.dirname
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger File.open(raw_path, "w"){|f| f.write raw_data }
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger # returns the raw data directly from the repository
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger def raw_data
ac24fe7991ded663db092bd5480ef9c52c14a86f= repository.read_file(ontology.path, commit_oid)[:content]
ac2169141f0b549fc8917a4b1d778f4ba3cab0bfJulian Kornberger end
aead985e48027c9df1ef553b17df29dd378757aaJulian Kornberger
a3923a34a7ada40e7db50fd8e58af228616f62c0Tim Reddehaseend