1 class ApplicationController < ActionController::Base
3 layout :devise_layout if MagicNumber['test_layout']
23 :location => {:controller => params[:controller], :action => params[:action]}
25 @server_result[:location][:id] = params[:id] if params[:id]
26 if Admin.count.to_i == 0 or License.count.to_i == 0
27 if params[:controller] == 'system' and params[:action] == 'start'
29 redirect_to :controller => '/system', :action => 'start'
32 user = if user_signed_in?
47 admin = if admin_signed_in?
52 demand_user = if demand_user_signed_in?
57 @operators = Operator.new [user, author, artist, admin, demand_user]
61 def authenticate_reader
62 authenticate_user! unless @operators.reader?
66 authenticate_user! unless @operators.user?
69 def authenticate_resource_reader
70 authenticate_user! unless @operators.resource_reader?
73 def authenticate_author
77 respond_to do |format|
78 format.html { redirect_to main_app.new_author_path, :status => :found }
79 format.js { render "authors/new" }
81 raise ActiveRecord::Forbidden
88 def authenticate_artist
92 respond_to do |format|
93 format.html { redirect_to main_app.new_artist_path, :status => :found }
94 format.js { render "artists/new" }
96 raise ActiveRecord::Forbidden
104 Pettanr::Application::manifest.controller_managers[self.model.item_name]
107 def self.profiler_manager
108 Pettanr::Application::manifest.profiler_managers[self.model.item_name]
112 action_name = params[:action]
113 @action = self.class.controller.open(action_name, params, @operators)
114 @items = @action.items
115 respond_to do |format|
117 @filer = @action.filer
118 render :template => 'system/filer', :locals => {
122 format.json { render json: @items.to_json(self.class.model.list_json_opt) }
128 def format_filer format
130 @paginate = @@model.list_paginate(@page, @page_size)
131 render :template => 'system/filer', :locals => {
132 :items => @items, :model => @@model,
133 :operators => @operators, :pager => @paginate
138 def format_prof format
140 @profiler = self.class.profiler_manager.open(@item, @operators)
141 render :template => 'system/prof', :locals => {
142 :profiler => @profiler
148 if file.respond_to?(:read)
151 Base64.decode64(file.to_s.gsub(' ', '+'))
155 def ymd_to_time ymd_str
156 return nil if ymd_str.blank?
159 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
166 def export_url demander_url, action, token, date
167 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
168 prm = '?auth_token=' + token
169 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
170 u = URI.join(u, action + '.json' + prm)
174 def export_from_provider url
177 json = RestClient.get url
178 res = JSON.parse json
184 def export_by action, provider_status, ymd
186 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
187 export_from_provider(url)
190 rescue_from Pettanr::NotWork, :with => :render_not_work
191 def render_not_work(exception = nil)
193 logger.info "Rendering , :: #{exception.message}"
195 respond_to do |format|
197 render :file => "#{Rails.root}/public/not_work.html", :layout => false
200 render :text => "400 Not work", :status => 400
205 if Rails.env == 'production'
206 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
207 rescue_from ActiveRecord::Forbidden, :with => :render_403
210 def render_404(exception = nil)
212 logger.info "Rendering 404: #{exception.message}"
214 respond_to do |format|
216 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
219 render :text => "404 Not found", :status => 404
224 def render_403(exception = nil)
226 logger.info "Rendering 403: #{exception.message}"
228 respond_to do |format|
230 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
233 render :text => "403 Forbidden", :status => 403