class DigitalAssetsController < ApplicationController include DigitalAssetsHelper respond_to :json, :html, :only => [:index, :show, :search, :fund_docs] skip_filter(*_process_action_callbacks.map(&:filter)) CACHE_LAST_PARSE_TIME = 'last_parse_time' # GET /digital_assets # GET /digital_assets.json def index @digital_assets = DigitalAsset.all respond_with(@digital_assets) end # GET /digital_assets/1 # GET /digital_assets/1.json def show @digital_asset = /\w{4,8}\.\d{0,3}/ =~ params[:id] ? DigitalAsset.sami_is(params[:id]).desc(:changed_at).first : DigitalAsset.find(params[:id]) respond_with(@digital_asset) end #/digital_assets/search/sami_code=92023 #/digital_assets/search/sami_code=NE00192&title=Fund%20Prospectus&fund_code=20293 def search @digital_assets = search_da(params) respond_with(@digital_assets) end def fund_docs @digital_assets = [] fund_doctypes = {:doctype => [ DigitalAsset::ContentType::PROSPECTUS, DigitalAsset::ContentType::SUMMARY_PROSPECTUS, DigitalAsset::ContentType::SAI, DigitalAsset::ContentType::ANNUAL_REPORT, DigitalAsset::ContentType::SEMIANNUAL_REPORT, DigitalAsset::ContentType::FACTSHEET, DigitalAsset::ContentType::COMMENTARY ]} @digital_assets = search_da(fund_doctypes) # remove anything that doesn't have a fundcode @digital_assets = @digital_assets.reject {|da| da.fund_code.nil?} respond_with(@digital_assets) end def sync_assets time0 = Rails.cache.read(CACHE_LAST_PARSE_TIME) if time0.nil? time0 = 2.days.ago end logger.info "Last time when ssc deploy files were read: #{time0.inspect}" time1 = Time.new logger.info "Current time: #{time1.inspect}" Rails.cache.write(CACHE_LAST_PARSE_TIME, time1) deploy_files= [] start_directory = EDIST['digital_assets_directory'] logger.info "Reading digital asset deployment files from #{start_directory}" if (File::directory?(start_directory)) Dir.foreach(start_directory) do |entry| if (!File::directory?(entry)) filename = start_directory + entry difference0 = File.mtime(filename)- time0 #To-Do - We should be looking at created time - ctime difference1 = File.mtime(filename) - time1 if ((difference0 >= 0) & (difference1 < 0)) if(/bulk-ssc_|selective-ssc_/ =~ filename) deploy_files << filename end end end end end deploy_files.each do |filename| #parse the file and add content to database. logger.info "Processing file #{filename} found." file = File.expand_path(filename, __FILE__) open_file = open(file, 'rb') Etl::TeamsiteMetadataParser.parse_tuple_file(open_file) logger.info "Finished parsing #{filename}." end head :accepted end end