app/controllers/digital_assets_controller.rb in daengine-0.5.13 vs app/controllers/digital_assets_controller.rb in daengine-0.6
- old
+ new
@@ -5,29 +5,52 @@
skip_filter(*_process_action_callbacks.map(&:filter))
CACHE_LAST_PARSE_TIME = 'last_parse_time'
# GET /digital_assets
# GET /digital_assets.json
+ #/digital_assets/search/sami_code=92023
+ #/digital_assets/search/sami_code=NE00192&title=Fund%20Prospectus&fund_code=20293
def index
- @digital_assets = DigitalAsset.all
+ @digital_assets = request.query_parameters.present? ? search_da(request.query_parameters) : DigitalAsset.all
respond_with(@digital_assets)
end
+ alias :search :index
# 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)
+ def update
+ da_passed = params[:digital_asset]
+ da = DigitalAsset.find_or_initialize_by(digital_asset_id: da_passed[:digital_asset_id])
+ da.update_attributes! da_passed
+ head :ok
end
+ alias :create :update
+
+ def destroy
+ da = DigitalAsset.where(:digital_asset_id => params[:id])
+ da[0].delete if da.present?
+ head :ok
+ end
+
+ def updated_time
+ Daengine.log "updated_time params #{params.inspect}", "info"
+ ids = params[:ids]
+ updated_time = Hash.new
+ ids.each do |id|
+ da = DigitalAsset.where(:digital_asset_id => id)
+ updated_time[id] = da[0].doc_changed_at if da.present?
+ end
+ Daengine.log "updated_time result #{updated_time.inspect}", "info"
+ render json: updated_time.to_json, status: :ok
+ end
+
def fund_docs
@digital_assets = []
fund_doctypes = {:doctype => [
DigitalAsset::ContentType::PROSPECTUS,
DigitalAsset::ContentType::SUMMARY_PROSPECTUS,
@@ -41,47 +64,7 @@
# 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