ontologies.rb revision edb0262a62074951f0d4997a783ce03eebc7c63e
2810N/Amodule Repository::Ontologies
2810N/A extend ActiveSupport::Concern
2810N/A
2810N/A # list all failed versions, grouped by their errors
2810N/A def failed_ontology_versions
2810N/A ontologies
2810N/A .without_parent
2810N/A .map{|o| o.versions.last}
2810N/A .compact
2810N/A .select{|v| v.state!="done"}
2810N/A .group_by(&:state_message)
2810N/A end
2810N/A
2810N/A def primary_ontology(path)
2810N/A path ||= ''
2810N/A onto = ontologies.where(basepath: File.basepath(path)).first
2810N/A while !onto.nil? && !onto.parent.nil?
2810N/A onto = onto.parent
2810N/A end
2810N/A
2810N/A onto
2810N/A end
6033N/A
2810N/A # Traverses a directory recursively, importing ontology file with supported
4070N/A # extension.
2810N/A #
2810N/A # @param user [User] the user that imports the ontology files
2810N/A # @param dir [String] the path to the ontology library
4070N/A #
6033N/A def import_ontologies(user, dir)
6033N/A Dir.glob("#{dir}/**/*.{#{Ontology::file_extensions.join(',')}}").each do |path|
2810N/A import_ontology(user, dir, path)
2810N/A end
2810N/A end
6033N/A
2810N/A # Imports an ontology in demand of a user.
2810N/A #
4676N/A # @param user [User] the user that imports the ontology file
2810N/A # @param repo [Repository] Repository, the files shall be saved in
6033N/A # @param path [String] the path to the ontology file
3661N/A #
3996N/A def import_ontology(user, dir, path)
3996N/A relpath = File.relative_path(dir, path)
3996N/A save_file(path, relpath, "Added #{relpath}.", user)
2810N/A end
2810N/A
2810N/Aend
2810N/A