OSDN Git Service

t#30487:fix export error v05port
authoryasushiito <yas@pen-chan.jp>
Mon, 21 Jan 2013 02:33:36 +0000 (11:33 +0900)
committeryasushiito <yas@pen-chan.jp>
Mon, 21 Jan 2013 02:33:36 +0000 (11:33 +0900)
app/controllers/application_controller.rb
app/controllers/provider_statuses_controller.rb
app/views/provider_statuses/artists_import.html.erb
app/views/provider_statuses/licenses_import.html.erb
app/views/provider_statuses/original_pictures_import.html.erb

index 3535232..c907a51 100644 (file)
@@ -108,8 +108,13 @@ class ApplicationController < ActionController::Base
   end
   
   def export_from_provider url
-    json = RestClient.get url
-    JSON.parse json
+    res = nil
+    begin
+      json = RestClient.get url
+      res = JSON.parse json
+    rescue
+    end
+    res
   end
   
   def export_by action, provider_status, ymd
index e40643a..0e865e0 100644 (file)
@@ -1,7 +1,31 @@
 class ProviderStatusesController < ApplicationController
   layout 'test' if MagicNumber['test_layout']
   before_filter :authenticate_admin!, :only => [:index, :show, :edit, :update, :destroy, :licenses_import, :artists_import, :original_pictures_import]
-
+  
+  private
+  
+  def licenses_port
+    licenses = export_by('licenses_export', @provider_status, params[:date])
+    return nil unless licenses
+    ProviderLicense.import @provider_status.provider.id, licenses
+  end
+  
+  def artists_port
+    artists = export_by('artists_export', @provider_status, params[:date])
+    return nil unless artists
+    ProviderArtist.import @provider_status.provider.id, artists
+  end
+  
+  def original_pictures_port
+    original_pictures = export_by('original_pictures_export', @provider_status, params[:date])
+    return nil unless original_pictures
+    pictures = export_by('pictures_export', @provider_status, params[:date])
+    return nil unless pictures
+    ProviderOriginalPicture.import @provider_status.provider.id, original_pictures, pictures
+  end
+  
+  public
+  
   def index
     @page = ProviderStatus.page params[:page]
     @page_size = ProviderStatus.page_size params[:page_size]
@@ -69,9 +93,7 @@ class ProviderStatusesController < ApplicationController
   def licenses_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    t = ymd_to_time params[:date]
-    url = export_url @provider_status.provider.demander_url, 'licenses_export', @provider_status.token, t
-    @failures = ProviderLicense.import @provider_status.provider.id, export_from_provider(url)
+    @failures = licenses_port
     respond_to do |format|
       format.html # show.html.erb
       format.json { render :json => @failures.to_json() }
@@ -81,9 +103,7 @@ class ProviderStatusesController < ApplicationController
   def artists_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    t = ymd_to_time params[:date]
-    url = export_url @provider_status.provider.demander_url, 'artists_export', @provider_status.token, t
-    @failures = ProviderArtist.import @provider_status.provider.id, export_from_provider(url)
+    @failures = artists_port
     respond_to do |format|
       format.html # show.html.erb
       format.json { render :json => @failures.to_json() }
@@ -93,9 +113,7 @@ class ProviderStatusesController < ApplicationController
   def original_pictures_import
     @provider_status = ProviderStatus.show(params[:id], @admin)
     raise ActiveRecord::Forbidden if @provider_status.status == 0
-    original_pictures = export_by('original_pictures_export', @provider_status, params[:date])
-    pictures = export_by('pictures_export', @provider_status, params[:date])
-    @failures = ProviderOriginalPicture.import @provider_status.provider.id, original_pictures, pictures
+    @failures = original_pictures_port
     respond_to do |format|
       format.html # show.html.erb
       format.json { render :json => @failures.to_json() }
index 0a0053a..1009327 100644 (file)
@@ -1,7 +1,9 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
-<% if @failures.empty? %>
+<% if @failures == nil %>
+  <h1>No Response</h1>
+<% elsif @failures.empty? %>
   <h2>
     <%= t('provider_statuses.artists_import.success') %>
   </h2>
index eb414cc..90e2022 100644 (file)
@@ -1,7 +1,9 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
-<% if @failures.empty? %>
+<% if @failures == nil %>
+  <h1>No Response</h1>
+<% elsif @failures.empty? %>
   <h2>
     <%= t('provider_statuses.licenses_import.success') %>
   </h2>
index 5d8d30c..728d7fd 100644 (file)
@@ -1,7 +1,9 @@
 <h1><%= t('.title') %></h1>
 <p id="notice"><%= notice %></p>
 
-<% if @failures[:original_pictures].any? %>
+<% if @failures == nil %>
+  <h1>No Response</h1>
+<% elsif @failures[:original_pictures].any? %>
   <h2>
     <%= t('provider_statuses.original_pictures_import.fail', :size => @failures[:original_pictures].size) %>
   </h2>