parsing.rb revision 6116d75120b5db0bcbc4a11abed8d0254ec85b8e
module OntologyVersion::Parsing
extend ActiveSupport::Concern
included do
@queue = 'hets'
after_create :async_parse, :if => :commit_oid?
attr_accessor :fast_parse
end
def do_not_parse!
@deactivate_parsing = true
end
def async_parse(*args)
if !@deactivate_parsing
update_state! :pending
if @fast_parse
async :parse_fast
else
async :parse_full
end
end
end
def parse(refresh_cache: false, structure_only: self.fast_parse)
# do_or_set_failed do
# condition = ['checksum = ? and id != ?', self.checksum, self.id]
# if OntologyVersion.where(condition).any?
# raise Exception.new('Another file with same checksum already exists.')
# end
# end
update_state! :processing
do_or_set_failed do
refresh_checksum! unless checksum?
# run hets if necessary
generate_xml(structure_only: structure_only) if refresh_cache || !xml_file?
# Import version
self.ontology.import_version self, self.user
update_state! :done
end
end
# generate XML by passing the raw ontology to Hets
def generate_xml(structure_only: false)
paths = Hets.parse(raw_path!, ontology.repository.url_maps, File.dirname(xml_path), structure_only: structure_only)
path = paths.last
# move generated file to destination
File.rename path, xml_path
end
def parse_full
parse(structure_only: false)
end
def parse_fast
parse(structure_only: true)
end
end