lib/iqvoc/skos_importer.rb in iqvoc-3.3.3 vs lib/iqvoc/skos_importer.rb in iqvoc-3.3.4

- old
+ new

@@ -5,11 +5,14 @@ SECOND_LEVEL_OBJECT_CLASSES = Iqvoc::Concept.labeling_classes.keys + Iqvoc::Concept.note_classes + Iqvoc::Concept.relation_classes + Iqvoc::Concept.match_classes - def initialize(file, default_namespace_url) + def initialize(file, default_namespace_url, logger = Rails.logger) + + @logger = logger + unless file.is_a?(File) || file.is_a?(Array) raise "Iqvoc::SkosImporter#import: Parameter 'file' should be a File or an Array." end # Some general Namespaces to support in any case @@ -60,11 +63,11 @@ new_subjects.each do |id, subject| if subject.valid_with_full_validation? subject.publish subject.save! else - Rails.logger.warn "WARNING: Subject not valid: '#{subject.origin}'. Won't be published automatically.." + @logger.warn "WARNING: Subject not valid: '#{subject.origin}'. Won't be published automatically.." end end end @@ -73,13 +76,13 @@ # We've found a subject definition with a class we know and which is in our responsibility (":") origin = $1 if (@existing_origins[origin]) if (types[object] == @existing_origins[origin]) - Rails.logger.info "Iqvoc::SkosImporter: Subject with origin '#{origin}' already exists. Skipping duplicate creation (should be no problem)." + @logger.info "Iqvoc::SkosImporter: Subject with origin '#{origin}' already exists. Skipping duplicate creation (should be no problem)." else - Rails.logger.warn "Iqvoc::SkosImporter: Subject with origin '#{origin} already exists but has another class (#{@existing_origins[origin]}) then the one I wanted to create (#{types[object]}). You seem to have a problem with your configuration!" + @logger.warn "Iqvoc::SkosImporter: Subject with origin '#{origin} already exists but has another class (#{@existing_origins[origin]}) then the one I wanted to create (#{types[object]}). You seem to have a problem with your configuration!" end else @seen_first_level_objects[origin] = types[object].create!(:origin => origin) end end @@ -90,19 +93,19 @@ # Load the subject and replace the string by the respective data object subject_origin = $1 subject = load_first_level_object(subject_origin) unless subject - Rails.logger.warn "Iqvoc::SkosImporter: Couldn't find Subject with origin '#{subject_origin}. Skipping entry '#{subject} #{predicate} #{object}.'" + @logger.warn "Iqvoc::SkosImporter: Couldn't find Subject with origin '#{subject_origin}. Skipping entry '#{subject} #{predicate} #{object}.'" return end # Load the data object for the object string if this is representing a thing in our domain if (object =~ /^:(.*)$/ && types[predicate]) object_origin = $1 object = load_first_level_object(object_origin) unless object - Rails.logger.warn "Iqvoc::SkosImporter: Couldn't find Object with origin '#{object_origin}. Skipping entry ':#{subject_origin} #{predicate} #{object}.'" + @logger.warn "Iqvoc::SkosImporter: Couldn't find Object with origin '#{object_origin}. Skipping entry ':#{subject_origin} #{predicate} #{object}.'" return end end types[predicate].build_from_rdf(subject, predicate, object)