require "daengine/version" require 'daengine/engine' require File.expand_path('../../app/models/digital_asset',__FILE__) require File.expand_path('../../app/models/taxonomy_term',__FILE__) require 'daengine/teamsite_metadata_parser' require 'daengine/digital_asset_processor' require 'daengine/taxonomy_parser' require 'daengine/taxonomy_processor' require 'mongoid' require 'logger' require 'nokogiri' module Daengine @logger = "/logs/daengine.log" @config = { :assets_path => '/digital-assets', :taxonomy_xml_filepath => '/taxonomy.xml' } @mongoid_config = { 'database' => 'ssc_assets_test', # mongoid database name 'host' => nil, # mongoid server 'port' => nil, # mongodb server port 'hosts' => nil } @valid_mongoid_keys = @mongoid_config.keys def self.log(message, level) message = "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] #{message}" puts "#{message}" case level when "warn" @logger.warn "#{message}" when "error" @logger.error "#{message}" else @logger.info "#{message}" end end # yaml file config def self.configure(config_options) config_options.each {|k,v| @config[k.to_sym] = v} config_options.each {|k,v| @mongoid_config[k] = v if @valid_mongoid_keys.include? k } @mongoid_config.delete_if { |k,v| ! v } Mongoid.configure do |config| config.from_hash(@mongoid_config) end end def self.config @config end def self.execute(config_options) self.configure(config_options) self.set_logger() self.log("Daengine: ### Loading application config ###", "info") config_options.each { |key, value| self.log("CONFIG #{key}\t#{value}", "info")} begin DigitalAssetProcessor.process_tuple_directory # start the thread daemon rescue Exception => e self.log(e.message, "error") end end def self.execute_taxonomy(config_options) self.configure(config_options) self.set_logger() self.log("Daengine: ### Loading application config ###", "info") config_options.each { |key, value| self.log("CONFIG #{key}\t#{value}", "info")} begin TaxonomyProcessor.process_taxonomy_file rescue Exception => e self.log(e.message, "error") end end def self.set_logger logfile = self.config[:logfile_location] @logger = Logger.new(logfile, 'daily') end def self.logger @logger end end