リビジョン | 0abef1b231256336612e82c288a821112795400b (tree) |
---|---|
日時 | 2013-04-27 14:16:12 |
作者 | ![]() |
コミッター | yasushiito |
Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05
@@ -69,37 +69,37 @@ class ProviderStatusesController < ApplicationController | ||
69 | 69 | def licenses_import |
70 | 70 | @provider_status = ProviderStatus.show(params[:id], @admin) |
71 | 71 | raise ActiveRecord::Forbidden if @provider_status.status == 0 |
72 | - @failures = @provider_status.licenses_import params[:date] | |
72 | + @import_result = @provider_status.licenses_import params[:date] | |
73 | 73 | respond_to do |format| |
74 | 74 | format.html # show.html.erb |
75 | - format.json { render :json => @failures.to_json() } | |
75 | + format.json { render :json => @import_result.to_json() } | |
76 | 76 | end |
77 | 77 | end |
78 | 78 | |
79 | 79 | def artists_import |
80 | 80 | @provider_status = ProviderStatus.show(params[:id], @admin) |
81 | 81 | raise ActiveRecord::Forbidden if @provider_status.status == 0 |
82 | - @failures = @provider_status.artists_import params[:date] | |
82 | + @import_result = @provider_status.artists_import params[:date] | |
83 | 83 | respond_to do |format| |
84 | 84 | format.html # show.html.erb |
85 | - format.json { render :json => @failures.to_json() } | |
85 | + format.json { render :json => @import_result.to_json() } | |
86 | 86 | end |
87 | 87 | end |
88 | 88 | |
89 | 89 | def original_pictures_import |
90 | 90 | @provider_status = ProviderStatus.show(params[:id], @admin) |
91 | 91 | raise ActiveRecord::Forbidden if @provider_status.status == 0 |
92 | - @failures = @provider_status.original_pictures_import params[:date] | |
92 | + @import_result = @provider_status.original_pictures_import params[:date] | |
93 | 93 | respond_to do |format| |
94 | 94 | format.html # show.html.erb |
95 | - format.json { render :json => @failures.to_json() } | |
95 | + format.json { render :json => @import_result.to_json() } | |
96 | 96 | end |
97 | 97 | end |
98 | 98 | |
99 | 99 | def import |
100 | 100 | @provider_status = ProviderStatus.show(params[:id], @admin) |
101 | 101 | raise ActiveRecord::Forbidden if @provider_status.status == 0 |
102 | - @failures = port | |
102 | + @import_result = @provider_status.import params[:date] | |
103 | 103 | respond_to do |format| |
104 | 104 | format.html # show.html.erb |
105 | 105 | format.json { render :json => @failures.to_json() } |
@@ -107,10 +107,8 @@ class ProviderStatusesController < ApplicationController | ||
107 | 107 | end |
108 | 108 | |
109 | 109 | def import_all |
110 | - ProviderStatus.find(:all).each do |provider_status| | |
111 | - next unless provider_status.status == 3 | |
112 | - @provider_status = provider_status | |
113 | - @failures = port | |
110 | + ProviderStatus.approve_list.each do |provider_status| | |
111 | + @provider_status = provider_status params[:date] | |
114 | 112 | end |
115 | 113 | respond_to do |format| |
116 | 114 | format.html { render :text => 'ok'} |
@@ -41,7 +41,7 @@ class ProviderArtist < ActiveRecord::Base | ||
41 | 41 | end |
42 | 42 | raise ActiveRecord::Rollback if res.any? |
43 | 43 | end |
44 | - res | |
44 | + ArtistImportResult.new res | |
45 | 45 | end |
46 | 46 | |
47 | 47 | end |
@@ -32,7 +32,7 @@ class ProviderLicense < ActiveRecord::Base | ||
32 | 32 | end |
33 | 33 | raise ActiveRecord::Rollback if res.any? |
34 | 34 | end |
35 | - res | |
35 | + LicenseImportResult.new res | |
36 | 36 | end |
37 | 37 | |
38 | 38 | end |
@@ -166,17 +166,24 @@ class ProviderOriginalPicture < ActiveRecord::Base | ||
166 | 166 | end |
167 | 167 | |
168 | 168 | def self.import pid, original_pictures, pictures |
169 | - res = {:original_pictures => [], :pictures => [], :resource_pictures => []} | |
169 | + res = nil | |
170 | 170 | ProviderOriginalPicture.transaction do |
171 | 171 | r = ProviderOriginalPicture.import_original_pictures(pid, original_pictures) |
172 | - res[:original_pictures] = r | |
173 | - raise ActiveRecord::Rollback if r.any? | |
172 | + if r.any? | |
173 | + res = OriginalPictureImportResult.new r | |
174 | + raise ActiveRecord::Rollback | |
175 | + end | |
174 | 176 | r = ProviderOriginalPicture.import_pictures(pid, pictures) |
175 | - res[:pictures] = r | |
176 | - raise ActiveRecord::Rollback if r.any? | |
177 | + if r.any? | |
178 | + res = PictureImportResult.new r | |
179 | + raise ActiveRecord::Rollback | |
180 | + end | |
177 | 181 | r = ProviderOriginalPicture.import_resource_pictures(pid, original_pictures) |
178 | - res[:resource_pictures] = r | |
179 | - raise ActiveRecord::Rollback if r.any? | |
182 | + if r.any? | |
183 | + res = ResourcePictureImportResult.new r | |
184 | + raise ActiveRecord::Rollback | |
185 | + end | |
186 | + res = OriginalPictureImportResult.new [] | |
180 | 187 | end |
181 | 188 | res |
182 | 189 | end |
@@ -123,12 +123,19 @@ class ProviderStatus < ActiveRecord::Base | ||
123 | 123 | end |
124 | 124 | |
125 | 125 | def ymd_to_time ymd_str |
126 | - return nil if ymd_str.blank? | |
127 | 126 | date = nil |
128 | - begin | |
129 | - date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7]) | |
130 | - rescue | |
131 | - date = nil | |
127 | + if ymd_str.blank? | |
128 | + date = if self.received_at | |
129 | + self.received_at | |
130 | + else | |
131 | + nil | |
132 | + end | |
133 | + else | |
134 | + begin | |
135 | + date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7]) | |
136 | + rescue | |
137 | + date = nil | |
138 | + end | |
132 | 139 | end |
133 | 140 | date |
134 | 141 | end |
@@ -159,41 +166,56 @@ class ProviderStatus < ActiveRecord::Base | ||
159 | 166 | |
160 | 167 | def licenses_import date |
161 | 168 | licenses = self.export_by('licenses_export', date) |
162 | - return nil unless licenses | |
163 | - ProviderLicense.import self.provider.id, licenses | |
169 | + if licenses | |
170 | + ProviderLicense.import self.provider.id, licenses | |
171 | + else | |
172 | + LicenseImportResult.new nil | |
173 | + end | |
164 | 174 | end |
165 | 175 | |
166 | 176 | def artists_import date |
167 | 177 | artists = self.export_by('artists_export', date) |
168 | - return nil unless artists | |
169 | - ProviderArtist.import self.provider.id, artists | |
178 | + if artists | |
179 | + ProviderArtist.import self.provider.id, artists | |
180 | + else | |
181 | + ArtistImportResult.new nil | |
182 | + end | |
170 | 183 | end |
171 | 184 | |
172 | 185 | def original_pictures_import date |
173 | 186 | original_pictures = self.export_by('original_pictures_export', date) |
174 | - return nil unless original_pictures | |
175 | 187 | pictures = self.export_by('pictures_export', date) |
176 | - return nil unless pictures | |
177 | - ProviderOriginalPicture.import self.provider.id, original_pictures, pictures | |
178 | - end | |
179 | - | |
180 | - def port | |
181 | - exports = export_by('export', @provider_status, params[:date]) | |
182 | - return nil unless exports | |
183 | - ProviderStatus.import @provider_status.provider.id, exports | |
188 | + if original_pictures and pictures | |
189 | + ProviderOriginalPicture.import self.provider.id, original_pictures, pictures | |
190 | + else | |
191 | + OriginalPictureImportResult.new nil | |
192 | + end | |
184 | 193 | end |
185 | 194 | |
186 | - def self.import pid, exports | |
187 | - res = {} | |
195 | + def import date | |
196 | + import_result = nil | |
188 | 197 | ProviderStatus.transaction do |
189 | - res[:licenses] = ProviderLicense.import pid, exports['licenses'] | |
190 | - raise ActiveRecord::Rollback if res[:licenses].any? | |
191 | - res[:artists] = ProviderArtist.import pid, exports['artists'] | |
192 | - raise ActiveRecord::Rollback if res[:artists].any? | |
193 | - res[:original_pictures] = ProviderOriginalPicture.import pid, exports['original_pictures'], exports['pictures'] | |
194 | - raise ActiveRecord::Rollback if res[:original_pictures][:original_pictures].any? or res[:original_pictures][:resource_pictures].any? or res[:original_pictures][:pictures].any? | |
198 | + import_result = self.licenses_import date | |
199 | + raise ActiveRecord::Rollback unless import_result.success? | |
200 | + import_result = self.artists_import date | |
201 | + raise ActiveRecord::Rollback unless import_result.success? | |
202 | + import_result = self.original_pictures_import date | |
203 | + raise ActiveRecord::Rollback unless import_result.success? | |
204 | + self.received_at = Time.now | |
205 | + self.save | |
195 | 206 | end |
196 | - res | |
207 | + import_result | |
197 | 208 | end |
198 | 209 | |
210 | + def self.import_all date = nil | |
211 | + failures = {} | |
212 | + ProviderStatus.approve_list.each do |provider_status| | |
213 | + import_result = provider_status.import date | |
214 | + next if import_result.success? | |
215 | + failures[provider_status.provider.name] = import_result | |
216 | + end | |
217 | + failures.each do |name, import_result| | |
218 | + puts name | |
219 | + end | |
220 | + end | |
199 | 221 | end |
@@ -1,18 +0,0 @@ | ||
1 | -<h2> | |
2 | - <%= t('provider_statuses.artists_import.fail', :size => failures.size) %> | |
3 | -</h2> | |
4 | -<table> | |
5 | - <tr> | |
6 | - <th><%= t_m 'Artist.name' -%></th> | |
7 | - </tr> | |
8 | - <% failures.each do |artist| %> | |
9 | - <tr> | |
10 | - <td> | |
11 | - <%= h(artist['name']) %> | |
12 | - </td> | |
13 | - <td> | |
14 | - <%= h(artist) %> | |
15 | - </td> | |
16 | - </tr> | |
17 | - <% end %> | |
18 | -</table> |
@@ -0,0 +1,19 @@ | ||
1 | +<h2> | |
2 | + <%= t("provider_statuses.#{import_result.translate}.fail", :size => import_result.failures.size) %> | |
3 | +</h2> | |
4 | +<table> | |
5 | + <tr> | |
6 | + <% import_result.columns.each do |column| %> | |
7 | + <th><%= t_m "#{import_result.obj}.#{column}" -%></th> | |
8 | + <% end %> | |
9 | + </tr> | |
10 | + <% import_result.failures.each do |failure| %> | |
11 | + <tr> | |
12 | + <% import_result.columns.each do |column| %> | |
13 | + <td> | |
14 | + <%= h(failure[column]) %> | |
15 | + </td> | |
16 | + <% end %> | |
17 | + </tr> | |
18 | + <% end %> | |
19 | +</table> |
@@ -1,19 +0,0 @@ | ||
1 | -<h2> | |
2 | - <%= t('provider_statuses.licenses_import.fail', :size => failures.size) %> | |
3 | -</h2> | |
4 | -<table> | |
5 | - <tr> | |
6 | - <th><%= t_m 'License.caption' -%></th> | |
7 | - <th><%= t_m 'License.name' -%></th> | |
8 | - </tr> | |
9 | - <% failures.each do |license| %> | |
10 | - <tr> | |
11 | - <td> | |
12 | - <%= link_to h(license['caption']), license['url'] %> | |
13 | - </td> | |
14 | - <td> | |
15 | - <%= h(license['name']) %> | |
16 | - </td> | |
17 | - </tr> | |
18 | - <% end %> | |
19 | -</table> |
@@ -1,23 +0,0 @@ | ||
1 | -<h2> | |
2 | - <%= t('provider_statuses.original_pictures_import.fail', :size => failures.size) %> | |
3 | -</h2> | |
4 | -<table> | |
5 | - <tr> | |
6 | - <th><%= t_m 'OriginalPicture.id' -%></th> | |
7 | - <th><%= t_m 'OriginalPicture.artist_id' -%></th> | |
8 | - <th><%= t_m 'OriginalPicture.md5' -%></th> | |
9 | - </tr> | |
10 | - <% failures.each do |original_picture| %> | |
11 | - <tr> | |
12 | - <td> | |
13 | - <%= h(original_picture['id']) %> | |
14 | - </td> | |
15 | - <td> | |
16 | - <%= h(original_picture['artist_id']) %> | |
17 | - </td> | |
18 | - <td> | |
19 | - <%= h(original_picture['md5']) %> | |
20 | - </td> | |
21 | - </tr> | |
22 | - <% end %> | |
23 | -</table> |
@@ -1,31 +0,0 @@ | ||
1 | -<h2> | |
2 | - <%= t('provider_statuses.pictures_import.fail', :size => failures.size) %> | |
3 | -</h2> | |
4 | -<table> | |
5 | - <tr> | |
6 | - <th><%= t_m 'Picture.id' -%></th> | |
7 | - <th><%= t_m 'Picture.original_picture_id' -%></th> | |
8 | - <th><%= t_m 'Picture.revision' -%></th> | |
9 | - <th><%= t_m 'Picture.artist_id' -%></th> | |
10 | - <th><%= t_m 'Picture.md5' -%></th> | |
11 | - </tr> | |
12 | - <% failures.each do |picture| %> | |
13 | - <tr> | |
14 | - <td> | |
15 | - <%= h(picture['id']) %> | |
16 | - </td> | |
17 | - <td> | |
18 | - <%= h(picture['original_picture_id']) %> | |
19 | - </td> | |
20 | - <td> | |
21 | - <%= h(picture['revision']) %> | |
22 | - </td> | |
23 | - <td> | |
24 | - <%= h(picture['artist_id']) %> | |
25 | - </td> | |
26 | - <td> | |
27 | - <%= h(picture['md5']) %> | |
28 | - </td> | |
29 | - </tr> | |
30 | - <% end %> | |
31 | -</table> |
@@ -1,31 +0,0 @@ | ||
1 | -<h2> | |
2 | - <%= t('provider_statuses.resource_pictures_import.fail', :size => failures.size) %> | |
3 | -</h2> | |
4 | -<table> | |
5 | - <tr> | |
6 | - <th><%= t_m 'ResourcePicture.id' -%></th> | |
7 | - <th><%= t_m 'ResourcePicture.original_picture_id' -%></th> | |
8 | - <th><%= t_m 'ResourcePicture.picture_id' -%></th> | |
9 | - <th><%= t_m 'ResourcePicture.artist_id' -%></th> | |
10 | - <th><%= t_m 'ResourcePicture.md5' -%></th> | |
11 | - </tr> | |
12 | - <% failures.each do |resource_picture| %> | |
13 | - <tr> | |
14 | - <td> | |
15 | - <%= h(resource_picture['id']) %> | |
16 | - </td> | |
17 | - <td> | |
18 | - <%= h(resource_picture['original_picture_id']) %> | |
19 | - </td> | |
20 | - <td> | |
21 | - <%= h(resource_picture['picture_id']) %> | |
22 | - </td> | |
23 | - <td> | |
24 | - <%= h(resource_picture['artist_id']) %> | |
25 | - </td> | |
26 | - <td> | |
27 | - <%= h(resource_picture['md5']) %> | |
28 | - </td> | |
29 | - </tr> | |
30 | - <% end %> | |
31 | -</table> |
@@ -1,13 +1,15 @@ | ||
1 | 1 | <h1><%= t('.title') %></h1> |
2 | 2 | <p id="notice"><%= notice %></p> |
3 | 3 | |
4 | -<% if @failures == nil %> | |
5 | - <h1>No Response</h1> | |
6 | -<% elsif @failures.empty? %> | |
7 | - <h2> | |
8 | - <%= t('provider_statuses.artists_import.success') %> | |
9 | - </h2> | |
4 | +<% if @import_result.response? %> | |
5 | + <% if @import_result.success? %> | |
6 | + <h2> | |
7 | + <%= t("provider_statuses.#{@import_result.action}.success") %> | |
8 | + </h2> | |
9 | + <% else %> | |
10 | + <%= render 'import_errors', :import_result => @import_result %> | |
11 | + <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %> | |
12 | + <% end %> | |
10 | 13 | <% else %> |
11 | - <%= render 'artists_errors', :failures => @failures %> | |
12 | - <%= link_to t('provider_statuses.artists_import.to_show'), provider_status_path(@provider_status) %> | |
14 | + <h1>No Response</h1> | |
13 | 15 | <% end %> |
@@ -1,20 +1,15 @@ | ||
1 | 1 | <h1><%= t('.title') %></h1> |
2 | 2 | <p id="notice"><%= notice %></p> |
3 | 3 | |
4 | -<% if @failures == nil %> | |
5 | - <h1>No Response</h1> | |
6 | -<% elsif @failures[:licenses].any? %> | |
7 | - <%= render 'licenses_errors', :failures => @failures[:licenses] %> | |
8 | -<% elsif @failures[:artists].any? %> | |
9 | - <%= render 'artists_errors', :failures => @failures[:artists] %> | |
10 | -<% elsif @failures[:original_pictures][:original_pictures].any? %> | |
11 | - <%= render 'original_pictures_errors', :failures => @failures[:original_pictures][:original_pictures] %> | |
12 | -<% elsif @failures[:original_pictures][:pictures].any? %> | |
13 | - <%= render 'pictures_errors', :failures => @failures[:original_pictures][:pictures] %> | |
14 | -<% elsif @failures[:original_pictures][:resource_pictures].any? %> | |
15 | - <%= render 'resource_pictures_errors', :failures => @failures[:original_pictures][:resource_pictures] %> | |
4 | +<% if @import_result.response? %> | |
5 | + <% if @import_result.success? %> | |
6 | + <h2> | |
7 | + <%= t("provider_statuses.import.success") %> | |
8 | + </h2> | |
9 | + <% else %> | |
10 | + <%= render 'import_errors', :import_result => @import_result %> | |
11 | + <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %> | |
12 | + <% end %> | |
16 | 13 | <% else %> |
17 | - <h2> | |
18 | - <%= t('provider_statuses.import.success') %> | |
19 | - </h2> | |
14 | + <h1>No Response</h1> | |
20 | 15 | <% end %> |
@@ -1,13 +1,15 @@ | ||
1 | 1 | <h1><%= t('.title') %></h1> |
2 | 2 | <p id="notice"><%= notice %></p> |
3 | 3 | |
4 | -<% if @failures == nil %> | |
5 | - <h1>No Response</h1> | |
6 | -<% elsif @failures.empty? %> | |
7 | - <h2> | |
8 | - <%= t('provider_statuses.licenses_import.success') %> | |
9 | - </h2> | |
4 | +<% if @import_result.response? %> | |
5 | + <% if @import_result.success? %> | |
6 | + <h2> | |
7 | + <%= t("provider_statuses.#{@import_result.action}.success") %> | |
8 | + </h2> | |
9 | + <% else %> | |
10 | + <%= render 'import_errors', :import_result => @import_result %> | |
11 | + <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %> | |
12 | + <% end %> | |
10 | 13 | <% else %> |
11 | - <%= render 'licenses_errors', :failures => @failures %> | |
12 | - <%= link_to t('provider_statuses.licenses_import.to_show'), provider_status_path(@provider_status) %> | |
14 | + <h1>No Response</h1> | |
13 | 15 | <% end %> |
@@ -1,19 +1,15 @@ | ||
1 | 1 | <h1><%= t('.title') %></h1> |
2 | 2 | <p id="notice"><%= notice %></p> |
3 | 3 | |
4 | -<% if @failures == nil %> | |
5 | - <h1>No Response</h1> | |
6 | -<% elsif @failures[:original_pictures].any? %> | |
7 | - <%= render 'original_pictures_errors', :failures => @failures[:original_pictures] %> | |
8 | - <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %> | |
9 | -<% elsif @failures[:pictures].any? %> | |
10 | - <%= render 'pictures_errors', :failures => @failures[:pictures] %> | |
11 | - <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %> | |
12 | -<% elsif @failures[:resource_pictures].any? %> | |
13 | - <%= render 'resource_pictures_errors', :failures => @failures[:resource_pictures] %> | |
14 | - <%= link_to t('provider_statuses.original_pictures_import.to_show'), provider_status_path(@provider_status) %> | |
4 | +<% if @import_result.response? %> | |
5 | + <% if @import_result.success? %> | |
6 | + <h2> | |
7 | + <%= t("provider_statuses.#{@import_result.action}.success") %> | |
8 | + </h2> | |
9 | + <% else %> | |
10 | + <%= render 'import_errors', :import_result => @import_result %> | |
11 | + <%= link_to t("provider_statuses.#{@import_result.action}.to_show"), provider_status_path(@provider_status) %> | |
12 | + <% end %> | |
15 | 13 | <% else %> |
16 | - <h2> | |
17 | - <%= t('provider_statuses.original_pictures_import.success') %> | |
18 | - </h2> | |
14 | + <h1>No Response</h1> | |
19 | 15 | <% end %> |
@@ -8,4 +8,5 @@ Pettanr::Application.initialize! | ||
8 | 8 | require 'picture_io' |
9 | 9 | require 'pettan_imager' |
10 | 10 | require 'ar_helper' |
11 | +require 'import_result' | |
11 | 12 |
@@ -0,0 +1,129 @@ | ||
1 | +# | |
2 | +class ImportResult | |
3 | + | |
4 | + def initialize results | |
5 | + @results = results | |
6 | + end | |
7 | + | |
8 | + def response? | |
9 | + @results != nil | |
10 | + end | |
11 | + | |
12 | + def success? | |
13 | + @results.empty? | |
14 | + end | |
15 | + | |
16 | + def failures | |
17 | + @results | |
18 | + end | |
19 | + | |
20 | + def to_json | |
21 | + if response? | |
22 | + @results.to_json | |
23 | + else | |
24 | + 'No Response' | |
25 | + end | |
26 | + end | |
27 | + | |
28 | +end | |
29 | + | |
30 | +class LicenseImportResult < ImportResult | |
31 | + | |
32 | + def columns | |
33 | + ['caption', 'name'] | |
34 | + end | |
35 | + | |
36 | + def obj | |
37 | + 'License' | |
38 | + end | |
39 | + | |
40 | + def action | |
41 | + 'licenses_import' | |
42 | + end | |
43 | + | |
44 | + def translate | |
45 | + 'licenses_import' | |
46 | + end | |
47 | + | |
48 | +end | |
49 | + | |
50 | +class ArtistImportResult < ImportResult | |
51 | + | |
52 | + def columns | |
53 | + ['name'] | |
54 | + end | |
55 | + | |
56 | + def obj | |
57 | + 'Artist' | |
58 | + end | |
59 | + | |
60 | + def action | |
61 | + 'artists_import' | |
62 | + end | |
63 | + | |
64 | + def translate | |
65 | + 'licenses_import' | |
66 | + end | |
67 | + | |
68 | +end | |
69 | + | |
70 | +class OriginalPictureImportResult < ImportResult | |
71 | + | |
72 | + def columns | |
73 | + ['id', 'artist_id', 'md5'] | |
74 | + end | |
75 | + | |
76 | + def obj | |
77 | + 'OriginalPicture' | |
78 | + end | |
79 | + | |
80 | + def action | |
81 | + 'original_pictures_import' | |
82 | + end | |
83 | + | |
84 | + def translate | |
85 | + 'original_pictures_import' | |
86 | + end | |
87 | + | |
88 | +end | |
89 | + | |
90 | +class ResourcePictureImportResult < ImportResult | |
91 | + | |
92 | + def columns | |
93 | + ['id', 'original_picture_id', 'picture_id', 'artist_id', 'md5'] | |
94 | + end | |
95 | + | |
96 | + def obj | |
97 | + 'ResourcePicture' | |
98 | + end | |
99 | + | |
100 | + def action | |
101 | + 'original_pictures_import' | |
102 | + end | |
103 | + | |
104 | + def translate | |
105 | + 'resource_pictures_import' | |
106 | + end | |
107 | + | |
108 | +end | |
109 | + | |
110 | +class PictureImportResult < ImportResult | |
111 | + | |
112 | + def columns | |
113 | + ['id', 'original_picture_id', 'revision', 'artist_id', 'md5'] | |
114 | + end | |
115 | + | |
116 | + def obj | |
117 | + 'Picture' | |
118 | + end | |
119 | + | |
120 | + def action | |
121 | + 'original_pictures_import' | |
122 | + end | |
123 | + | |
124 | + def translate | |
125 | + 'pictures_import' | |
126 | + end | |
127 | + | |
128 | +end | |
129 | + |
@@ -369,7 +369,7 @@ describe ProviderStatusesController do | ||
369 | 369 | context '事前チェックしておく' do |
370 | 370 | before do |
371 | 371 | ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) |
372 | - ProviderStatus.stub(:licenses_import).with(any_args).and_return([]) | |
372 | + ProviderStatus.stub(:licenses_import).with(any_args).and_return(LicenseImportResult.new([])) | |
373 | 373 | end |
374 | 374 | it '借受状況モデルに単体取得を問い合わせている' do |
375 | 375 | ProviderStatus.should_receive(:show).exactly(1) |
@@ -383,7 +383,7 @@ describe ProviderStatusesController do | ||
383 | 383 | context 'つつがなく終わるとき' do |
384 | 384 | before do |
385 | 385 | ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) |
386 | - ProviderStatus.any_instance.stub(:licenses_import).with(any_args).and_return([]) | |
386 | + ProviderStatus.any_instance.stub(:licenses_import).with(any_args).and_return(LicenseImportResult.new([])) | |
387 | 387 | end |
388 | 388 | it 'ステータスコード200 OKを返す' do |
389 | 389 | get :licenses_import, :id => @ps.id |
@@ -393,9 +393,9 @@ describe ProviderStatusesController do | ||
393 | 393 | get :licenses_import, :id => @ps.id |
394 | 394 | assigns(:provider_status).should eq(@ps) |
395 | 395 | end |
396 | - it '@failuresにインポート失敗リストを取得している' do | |
396 | + it '@import_resultにインポート結果を取得している' do | |
397 | 397 | get :licenses_import, :id => @ps.id |
398 | - assigns(:failures).should eq([]) | |
398 | + assigns(:import_result).is_a?(ImportResult).should be_true | |
399 | 399 | end |
400 | 400 | context 'html形式' do |
401 | 401 | it 'licenses_importテンプレートを描画する' do |
@@ -466,7 +466,7 @@ describe ProviderStatusesController do | ||
466 | 466 | context '事前チェックしておく' do |
467 | 467 | before do |
468 | 468 | ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) |
469 | - ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return([]) | |
469 | + ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return(ArtistImportResult.new([])) | |
470 | 470 | end |
471 | 471 | it '借受状況モデルに単体取得を問い合わせている' do |
472 | 472 | ProviderStatus.should_receive(:show).exactly(1) |
@@ -480,7 +480,7 @@ describe ProviderStatusesController do | ||
480 | 480 | context 'つつがなく終わるとき' do |
481 | 481 | before do |
482 | 482 | ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) |
483 | - ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return([]) | |
483 | + ProviderStatus.any_instance.stub(:artists_import).with(any_args).and_return(ArtistImportResult.new([])) | |
484 | 484 | end |
485 | 485 | it 'ステータスコード200 OKを返す' do |
486 | 486 | get :artists_import, :id => @ps.id |
@@ -490,9 +490,9 @@ describe ProviderStatusesController do | ||
490 | 490 | get :artists_import, :id => @ps.id |
491 | 491 | assigns(:provider_status).should eq(@ps) |
492 | 492 | end |
493 | - it '@failuresにインポート失敗リストを取得している' do | |
493 | + it '@import_resultにインポート結果を取得している' do | |
494 | 494 | get :artists_import, :id => @ps.id |
495 | - assigns(:failures).should eq([]) | |
495 | + assigns(:import_result).is_a?(ImportResult).should be_true | |
496 | 496 | end |
497 | 497 | context 'html形式' do |
498 | 498 | it 'artists_importテンプレートを描画する' do |
@@ -572,7 +572,7 @@ describe ProviderStatusesController do | ||
572 | 572 | context '事前チェックしておく' do |
573 | 573 | before do |
574 | 574 | ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) |
575 | - ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []}) | |
575 | + ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return(OriginalPictureImportResult.new([])) | |
576 | 576 | end |
577 | 577 | it '借受状況モデルに単体取得を問い合わせている' do |
578 | 578 | ProviderStatus.should_receive(:show).exactly(1) |
@@ -586,7 +586,7 @@ describe ProviderStatusesController do | ||
586 | 586 | context 'つつがなく終わるとき' do |
587 | 587 | before do |
588 | 588 | ProviderStatus.any_instance.stub(:status).with(any_args).and_return(1) |
589 | - ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []}) | |
589 | + ProviderStatus.any_instance.stub(:original_pictures_import).with(any_args).and_return(OriginalPictureImportResult.new([])) | |
590 | 590 | end |
591 | 591 | it 'ステータスコード200 OKを返す' do |
592 | 592 | get :original_pictures_import, :id => @ps.id |
@@ -596,12 +596,9 @@ describe ProviderStatusesController do | ||
596 | 596 | get :original_pictures_import, :id => @ps.id |
597 | 597 | assigns(:provider_status).should eq(@ps) |
598 | 598 | end |
599 | - it '@failuresにインポート失敗リストを取得している' do | |
599 | + it '@import_resultにインポート結果を取得している' do | |
600 | 600 | get :original_pictures_import, :id => @ps.id |
601 | - assigns(:failures).should_not be_nil | |
602 | - assigns(:failures)[:original_pictures].should be_empty | |
603 | - assigns(:failures)[:pictures].should be_empty | |
604 | - assigns(:failures)[:resource_pictures].should be_empty | |
601 | + assigns(:import_result).is_a?(ImportResult).should be_true | |
605 | 602 | end |
606 | 603 | context 'html形式' do |
607 | 604 | it 'artists_importテンプレートを描画する' do |
@@ -143,9 +143,10 @@ describe ProviderArtist do | ||
143 | 143 | end |
144 | 144 | end |
145 | 145 | context 'つつがなく終わるとき' do |
146 | - it '空っぽの配列を返す' do | |
146 | + it 'ImportResultを返す' do | |
147 | 147 | r = ProviderArtist.import @provider.id, [@artist.attributes] |
148 | - r.should be_empty | |
148 | + r.is_a?(ImportResult).should be_true | |
149 | + r.should be_success | |
149 | 150 | end |
150 | 151 | it '対照表が追加される' do |
151 | 152 | lambda { |
@@ -154,9 +155,10 @@ describe ProviderArtist do | ||
154 | 155 | end |
155 | 156 | end |
156 | 157 | context '複数インポートのとき' do |
157 | - it '空っぽの配列を返す' do | |
158 | + it 'ImportResultを返す' do | |
158 | 159 | r = ProviderArtist.import @provider.id, [@artist.attributes, @artist2.attributes] |
159 | - r.should be_empty | |
160 | + r.is_a?(ImportResult).should be_true | |
161 | + r.should be_success | |
160 | 162 | end |
161 | 163 | it '対照表が追加される' do |
162 | 164 | lambda { |
@@ -169,18 +171,20 @@ describe ProviderArtist do | ||
169 | 171 | before do |
170 | 172 | ProviderArtist.any_instance.stub(:save).with(any_args).and_return(false) |
171 | 173 | end |
172 | - it '結果に貸手側絵師のカラム値を追加している' do | |
174 | + it '結果が失敗している' do | |
173 | 175 | r = ProviderArtist.import @provider.id, [@artist.attributes] |
174 | - r.should_not be_empty | |
176 | + r.should_not be_success | |
177 | + r.failures.should_not be_empty | |
175 | 178 | end |
176 | 179 | end |
177 | 180 | context '絵師オブジェクトの保存に失敗したとき' do |
178 | 181 | before do |
179 | 182 | Artist.any_instance.stub(:save).with(any_args).and_return(false) |
180 | 183 | end |
181 | - it '結果に貸手側絵師のカラム値を追加している' do | |
184 | + it '結果が失敗している' do | |
182 | 185 | r = ProviderArtist.import @provider.id, [@artist.attributes] |
183 | - r.should_not be_empty | |
186 | + r.should_not be_success | |
187 | + r.failures.should_not be_empty | |
184 | 188 | end |
185 | 189 | end |
186 | 190 | end |
@@ -101,9 +101,10 @@ describe ProviderLicense do | ||
101 | 101 | end |
102 | 102 | end |
103 | 103 | context 'つつがなく終わるとき' do |
104 | - it '空っぽの配列を返す' do | |
104 | + it 'ImportResultを返す' do | |
105 | 105 | r = ProviderLicense.import @provider.id, [@license.attributes] |
106 | - r.should be_empty | |
106 | + r.is_a?(ImportResult).should be_true | |
107 | + r.should be_success | |
107 | 108 | end |
108 | 109 | it '対照表が追加される' do |
109 | 110 | lambda { |
@@ -112,9 +113,10 @@ describe ProviderLicense do | ||
112 | 113 | end |
113 | 114 | end |
114 | 115 | context '複数インポートのとき' do |
115 | - it '空っぽの配列を返す' do | |
116 | + it 'ImportResultを返す' do | |
116 | 117 | r = ProviderLicense.import @provider.id, [@license.attributes, @license2.attributes] |
117 | - r.should be_empty | |
118 | + r.is_a?(ImportResult).should be_true | |
119 | + r.should be_success | |
118 | 120 | end |
119 | 121 | it '対照表が追加される' do |
120 | 122 | lambda { |
@@ -127,18 +129,20 @@ describe ProviderLicense do | ||
127 | 129 | before do |
128 | 130 | ProviderLicense.any_instance.stub(:save).with(any_args).and_return(false) |
129 | 131 | end |
130 | - it '結果に貸手側ライセンスのカラム値を追加している' do | |
132 | + it '結果が失敗している' do | |
131 | 133 | r = ProviderLicense.import @provider.id, [@license.attributes] |
132 | - r.should_not be_empty | |
134 | + r.should_not be_success | |
135 | + r.failures.should_not be_empty | |
133 | 136 | end |
134 | 137 | end |
135 | 138 | context 'ライセンスの管理名取得に失敗したとき' do |
136 | 139 | before do |
137 | 140 | License.stub(:find_by_name).with(any_args).and_return(nil) |
138 | 141 | end |
139 | - it '結果に貸手側ライセンスのカラム値を追加している' do | |
142 | + it '結果が失敗している' do | |
140 | 143 | r = ProviderLicense.import @provider.id, [@license.attributes] |
141 | - r.should_not be_empty | |
144 | + r.should_not be_success | |
145 | + r.failures.should_not be_empty | |
142 | 146 | end |
143 | 147 | end |
144 | 148 | end |
@@ -882,11 +882,10 @@ describe ProviderOriginalPicture do | ||
882 | 882 | ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([]) |
883 | 883 | ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([]) |
884 | 884 | end |
885 | - it '各失敗したカラム値をHashで返す' do | |
885 | + it 'ImportResultを返す' do | |
886 | 886 | r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr] |
887 | - r[:original_pictures].should be_empty | |
888 | - r[:pictures].should be_empty | |
889 | - r[:resource_pictures].should be_empty | |
887 | + r.is_a?(ImportResult).should be_true | |
888 | + r.should be_success | |
890 | 889 | end |
891 | 890 | end |
892 | 891 | #警告ケース |
@@ -896,11 +895,11 @@ describe ProviderOriginalPicture do | ||
896 | 895 | ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([]) |
897 | 896 | ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([]) |
898 | 897 | end |
899 | - it '失敗した原画のカラム値を配列でoriginal_picturesに追加している' do | |
898 | + it '結果が失敗している' do | |
900 | 899 | r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr] |
901 | - r[:original_pictures].should_not be_empty | |
902 | - r[:pictures].should be_empty | |
903 | - r[:resource_pictures].should be_empty | |
900 | + r.should_not be_success | |
901 | + r.is_a?(OriginalPictureImportResult).should be_true | |
902 | + r.failures.should_not be_empty | |
904 | 903 | end |
905 | 904 | end |
906 | 905 | context '実素材インポートに失敗したとき' do |
@@ -909,11 +908,11 @@ describe ProviderOriginalPicture do | ||
909 | 908 | ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([@pattr]) |
910 | 909 | ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([]) |
911 | 910 | end |
912 | - it '失敗した原画のカラム値を配列でpicturesに追加している' do | |
911 | + it '結果が失敗している' do | |
913 | 912 | r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr] |
914 | - r[:original_pictures].should be_empty | |
915 | - r[:pictures].should_not be_empty | |
916 | - r[:resource_pictures].should be_empty | |
913 | + r.should_not be_success | |
914 | + r.is_a?(PictureImportResult).should be_true | |
915 | + r.failures.should_not be_empty | |
917 | 916 | end |
918 | 917 | end |
919 | 918 | context '素材インポートに失敗したとき' do |
@@ -922,11 +921,11 @@ describe ProviderOriginalPicture do | ||
922 | 921 | ProviderOriginalPicture.stub(:import_pictures).with(any_args).and_return([]) |
923 | 922 | ProviderOriginalPicture.stub(:import_resource_pictures).with(any_args).and_return([@rpattr]) |
924 | 923 | end |
925 | - it '失敗した原画のカラム値を配列でresource_picturesに追加している' do | |
924 | + it '結果が失敗している' do | |
926 | 925 | r = ProviderOriginalPicture.import @provider.id, [@opattr], [@pattr] |
927 | - r[:original_pictures].should be_empty | |
928 | - r[:pictures].should be_empty | |
929 | - r[:resource_pictures].should_not be_empty | |
926 | + r.should_not be_success | |
927 | + r.is_a?(ResourcePictureImportResult).should be_true | |
928 | + r.failures.should_not be_empty | |
930 | 929 | end |
931 | 930 | end |
932 | 931 | end |
@@ -636,7 +636,7 @@ describe ProviderStatus do | ||
636 | 636 | context '事前チェックしておく' do |
637 | 637 | before do |
638 | 638 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([@license.attributes]) |
639 | - ProviderLicense.stub(:import).with(any_args).and_return([]) | |
639 | + ProviderLicense.stub(:import).with(any_args).and_return(LicenseImportResult.new([])) | |
640 | 640 | end |
641 | 641 | it '貸手からのエクスポートを依頼している' do |
642 | 642 | ProviderStatus.any_instance.should_receive(:export_by).exactly(1) |
@@ -650,20 +650,20 @@ describe ProviderStatus do | ||
650 | 650 | context 'つつがなく終わるとき' do |
651 | 651 | before do |
652 | 652 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([@license.attributes]) |
653 | - ProviderLicense.stub(:import).with(any_args).and_return([]) | |
653 | + ProviderLicense.stub(:import).with(any_args).and_return(LicenseImportResult.new([])) | |
654 | 654 | end |
655 | 655 | it 'ライセンスインポート結果を返す' do |
656 | 656 | r = @ps.licenses_import '20111010' |
657 | - r.should eq [] | |
657 | + r.should be_response | |
658 | 658 | end |
659 | 659 | end |
660 | 660 | context 'エクスポートに失敗したとき' do |
661 | 661 | before do |
662 | 662 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil) |
663 | 663 | end |
664 | - it 'nilを返す' do | |
664 | + it '受信に失敗したImportResultを返す' do | |
665 | 665 | r = @ps.licenses_import '20111010' |
666 | - r.should be_nil | |
666 | + r.should_not be_response | |
667 | 667 | end |
668 | 668 | end |
669 | 669 | end |
@@ -676,7 +676,7 @@ describe ProviderStatus do | ||
676 | 676 | context '事前チェックしておく' do |
677 | 677 | before do |
678 | 678 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([]) |
679 | - ProviderArtist.stub(:import).with(any_args).and_return([]) | |
679 | + ProviderArtist.stub(:import).with(any_args).and_return(ArtistImportResult.new([])) | |
680 | 680 | end |
681 | 681 | it '貸手からのエクスポートを依頼している' do |
682 | 682 | ProviderStatus.any_instance.should_receive(:export_by).exactly(1) |
@@ -690,20 +690,20 @@ describe ProviderStatus do | ||
690 | 690 | context 'つつがなく終わるとき' do |
691 | 691 | before do |
692 | 692 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([]) |
693 | - ProviderArtist.stub(:import).with(any_args).and_return([]) | |
693 | + ProviderArtist.stub(:import).with(any_args).and_return(ArtistImportResult.new([])) | |
694 | 694 | end |
695 | 695 | it '絵師インポート結果を返す' do |
696 | 696 | r = @ps.artists_import '20111010' |
697 | - r.should eq [] | |
697 | + r.should be_response | |
698 | 698 | end |
699 | 699 | end |
700 | 700 | context 'エクスポートに失敗したとき' do |
701 | 701 | before do |
702 | 702 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil) |
703 | 703 | end |
704 | - it 'nilを返す' do | |
705 | - r = @ps.artists_import '20111010' | |
706 | - r.should be_nil | |
704 | + it '受信に失敗したImportResultを返す' do | |
705 | + r = @ps.licenses_import '20111010' | |
706 | + r.should_not be_response | |
707 | 707 | end |
708 | 708 | end |
709 | 709 | end |
@@ -716,7 +716,7 @@ describe ProviderStatus do | ||
716 | 716 | context '事前チェックしておく' do |
717 | 717 | before do |
718 | 718 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([]) |
719 | - ProviderOriginalPicture.stub(:import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []}) | |
719 | + ProviderOriginalPicture.stub(:import).with(any_args).and_return(OriginalPictureImportResult.new([])) | |
720 | 720 | end |
721 | 721 | it '貸手からのエクスポートを依頼している' do |
722 | 722 | ProviderStatus.any_instance.should_receive(:export_by).exactly(2) |
@@ -730,26 +730,20 @@ describe ProviderStatus do | ||
730 | 730 | context 'つつがなく終わるとき' do |
731 | 731 | before do |
732 | 732 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return([]) |
733 | - ProviderOriginalPicture.stub(:import).with(any_args).and_return({:original_pictures => [], :pictures => [], :resource_pictures => []}) | |
733 | + ProviderOriginalPicture.stub(:import).with(any_args).and_return(OriginalPictureImportResult.new([])) | |
734 | 734 | end |
735 | 735 | it '原画インポート結果を返す' do |
736 | 736 | r = @ps.original_pictures_import '20111010' |
737 | - r.is_a?(Hash).should be_true | |
738 | - end | |
739 | - it 'インポート失敗リストを取得している' do | |
740 | - r = @ps.original_pictures_import '20111010' | |
741 | - r[:original_pictures].should be_empty | |
742 | - r[:pictures].should be_empty | |
743 | - r[:resource_pictures].should be_empty | |
737 | + r.should be_response | |
744 | 738 | end |
745 | 739 | end |
746 | 740 | context 'エクスポートに失敗したとき' do |
747 | 741 | before do |
748 | 742 | ProviderStatus.any_instance.stub(:export_by).with(any_args).and_return(nil) |
749 | 743 | end |
750 | - it 'nilを返す' do | |
751 | - r = @ps.original_pictures_import '20111010' | |
752 | - r.should be_nil | |
744 | + it '受信に失敗したImportResultを返す' do | |
745 | + r = @ps.licenses_import '20111010' | |
746 | + r.should_not be_response | |
753 | 747 | end |
754 | 748 | end |
755 | 749 | end |