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 File.expand_path('../../app/models/content_service_resource',__FILE__) require 'mini_exiftool' require 'daengine/teamsite_metadata_parser' require 'daengine/digital_asset_processor' require 'daengine/taxonomy_parser' require 'daengine/taxonomy_processor' require 'daengine/content_service_processor' require 'mongoid' require 'logger' require 'nokogiri' module Daengine @logger @config = { :assets_path => '/digital-assets', :taxonomy_xml_filepath => '/taxonomy.xml', :content_service_url => 'http://ofiwsqa.den.ofi.com/' } @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(config[:logfile_location]) 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(config[:taxonomyengine_logfile_location]) 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.execute_content_service(config_options) self.configure(config_options) self.set_logger(config[:content_service_logfile_location]) self.log("Daengine: ### Loading application config ###", "info") config_options.each { |key, value| self.log("CONFIG #{key}\t#{value}", "info")} begin ContentServiceProcessor.process_orderable rescue Exception => e self.log(e.message, "error") end end def self.set_logger(logfile) @logger = Logger.new(logfile, 'daily') end def self.logger @logger end end