go_import 3.0.25 → 3.0.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmI2ODQ1ZjgzODEyYzNiMjI3NjQ3OWFhNGQ4MmVjNjYzYjgyYjhiOQ==
4
+ ZjBiMjk3NmIxNjgwZDNhYjI2M2M2MWEwYjUxMzgyODQ2MmNmNmE4NQ==
5
5
  data.tar.gz: !binary |-
6
- NDgwNjJkOTFlODBjMWRiYmJiNGViZGUxZDJkODBjZjVlMWFmZmNhZg==
6
+ NTRkOGI4YTZiYjY5YzI5OTk0ZThlOWY4ZWY3NzM3YTBlNzMwMDk1MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmI0N2U5N2MwYWZiMDlkNTExMmJmM2VjZjIyY2M2NzQ4NjNhMzgxNTUxNWI4
10
- ZjJhZmU0MmMxOTBkNzkyNmY3ZjNiZTMyMzNiYTE5ZWMxMTE4MjY2Yzc0MzNl
11
- NzE5YWVmNGQ0YmI3MzcxZmY4NDA5NjlhNGUwYTM5NzVkZWM2MDU=
9
+ M2JjMjNhNTc4ZTI0ODc2YTRjODU5YzFmODA2NDEzM2ZjZDI2YjE2ZTgwNGM5
10
+ Yjk3NjBhN2IxN2NhMzFhNzEzOGY0NTUxZWUzNjMxMmIxMzc3YWZiMDAwOTI3
11
+ M2E0Y2U3MzI0OGUxMWExNGI0ZTg2YTRkNDdiOGQzMzUwNjRkNGE=
12
12
  data.tar.gz: !binary |-
13
- NjYwMmMyZTdkMDQzOTUyZDU0ZWIyOTU0NGY0ZTRjMGVjOTMyYmM3Yjg1YTIx
14
- OGUyNjg5MDU0Y2ZiNWI3ZWUyOTQxMmY4M2ZiYjcwOTgwMTdlOTc2OTkwNjYw
15
- MzU1MTM1NWU5ZDU4OWVjOWRjMmQwYjdkNWVlNjc2MTUxMDJiZjA=
13
+ MDE0MmJmNjliY2Y4MjBkNDk3MTNhNGNjMjljZTMyNmE5YTNiOGNjMzEyMjNk
14
+ NzdiZWFkZjhiZjQ0ZTYzODRhNmIzM2YwZTYwOWRhM2ZhNzA3NGMxMmI0OTgw
15
+ MDViZGJhODNiYjJkYTdmMmRmOTVkY2YyYzE0OWYyNzQzZGZiZDQ=
data/bin/go-import CHANGED
@@ -50,8 +50,8 @@ class GoImportCommandLine < Thor
50
50
  :desc => "Name of the file where the converted source will be saved. This file should be sent to LIME Go. If the file already exist it will be replaced.",
51
51
  :type => :string,
52
52
  :required => false)
53
- option(:ignore_missing_files,
54
- :desc => "Output will be created even if the import contains missing files",
53
+ option(:ignore_invalid_files,
54
+ :desc => "Output will be created even if the import contains missing or invalid files",
55
55
  :type => :boolean,
56
56
  :required => false)
57
57
  option(:log_to_file,
@@ -82,36 +82,43 @@ class GoImportCommandLine < Thor
82
82
  puts "WARNING: This means that files with an absolute path will be imported with their original path. Set this constant if you want to get files from the FILES_FOLDER directory."
83
83
  end
84
84
 
85
- is_ok, error_msg = can_be_serialized?(model, options.ignore_missing_files)
85
+ is_ok, error_msg, warnings_msg = can_be_serialized?(model, options.ignore_invalid_files)
86
86
  if is_ok
87
- if options.ignore_missing_files && model.documents.files.length > 0
88
- log_and_remove_missing_files model
87
+ if options.ignore_invalid_files && model.documents.files.length > 0
88
+ log_and_remove_invalid_files model
89
89
  end
90
90
 
91
91
  go_data_zip = options.output.nil? == true ? "go.zip" : options.output
92
92
  model.save_to_zip(go_data_zip)
93
93
  puts "Source has been been converted into '#{go_data_zip}'."
94
+ if !warnings_msg.empty?
95
+ puts "WARNINGS: "
96
+ puts warnings_msg
97
+ end
94
98
  else
95
99
  puts "ERROR: Source could not be converted due to:"
96
100
  puts error_msg
97
101
 
98
- if !options.ignore_missing_files &&
99
- model.documents.files.any? {|file| !::File.exists?(file.path_for_project)}
100
- puts "go-import detected missing files (see above), you can ignore these with the option --ignore-missing-files."
102
+ if !options.ignore_invalid_files &&
103
+ model.documents.files.any? {|file| file.validate.empty?}
104
+ puts "go-import detected invalid files (see above), you can ignore these with the option --ignore-invalid-files."
101
105
  end
102
106
  end
103
107
  end
104
108
 
105
109
  private
106
- def log_and_remove_missing_files(model)
110
+ def log_and_remove_invalid_files(model)
107
111
  if model.documents.files.length > 0
108
112
  puts "Trying to log files that can't be found..."
109
- file_log_header = "name;integration_id;path;organization.integrationid;organization.name;deal.integrationid;deal.name"
113
+ file_log_header = "name;integration_id;path;organization.integrationid;organization.name;deal.integrationid;deal.name;file.size"
110
114
  file_log = ""
111
115
  files_to_remove = []
112
116
  model.documents.files.each do |file|
113
117
  if !::File.exists?(file.path_for_project)
114
- file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name}\n"
118
+ file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name};0\n"
119
+ files_to_remove.push file
120
+ elsif ::File.size(file.path_for_project) > GoImport::File::MAX_FILE_SIZE
121
+ file_log = "#{file_log}#{file.name};#{file.integration_id};#{file.path};#{file.organization.nil? ? '' : file.organization.integration_id};#{file.organization.nil? ? '' : file.organization.name};#{file.deal.nil? ? '' : file.deal.integration_id};#{file.deal.nil? ? '' : file.deal.name};#{::File.size(file.path_for_project)}\n"
115
122
  files_to_remove.push file
116
123
  end
117
124
  end
@@ -121,12 +128,12 @@ class GoImportCommandLine < Thor
121
128
  end
122
129
 
123
130
  if file_log.length > 0
124
- log_filename = 'go-import-missing-files.csv'
131
+ log_filename = 'go-import-invalid-files.csv'
125
132
  ::File.open(log_filename, 'w') { |f|
126
133
  f.puts file_log_header
127
134
  f.puts file_log
128
135
  }
129
- puts "WARNING: go-import has ignored files. Filenames of all ignored files has been written to '#{log_filename}'."
136
+ puts "WARNING: go-import has invalid files. Filenames of all ignored files has been written to '#{log_filename}'."
130
137
  else
131
138
  puts "All files are OK."
132
139
  end
@@ -134,18 +141,18 @@ class GoImportCommandLine < Thor
134
141
  end
135
142
 
136
143
  private
137
- def can_be_serialized?(rootmodel, ignore_missing_files)
144
+ def can_be_serialized?(rootmodel, ignore_invalid_files)
138
145
  is_ok = false
139
146
  error = rootmodel.sanity_check
140
147
  if error.empty?
141
- error = rootmodel.validate(ignore_missing_files)
148
+ error, warnings = rootmodel.validate(ignore_invalid_files)
142
149
 
143
150
  if error.empty?
144
151
  is_ok = true
145
152
  end
146
153
  end
147
154
 
148
- return [is_ok, error]
155
+ return [is_ok, error, warnings]
149
156
  end
150
157
 
151
158
  private
@@ -33,7 +33,11 @@ module GoImport
33
33
  when 'Sverige'
34
34
  'SE'
35
35
  else
36
- IsoCountryCodes.search_by_name(name).first.alpha2
36
+ begin
37
+ IsoCountryCodes.search_by_name(name).first.alpha2
38
+ rescue
39
+ nil
40
+ end
37
41
  end
38
42
  end
39
43
  # parses a line like "226 48 LUND" into its corresponding
@@ -55,7 +59,5 @@ module GoImport
55
59
  end
56
60
  return nil
57
61
  end
58
-
59
-
60
62
  end
61
- end
63
+ end
@@ -91,8 +91,9 @@ module GoImport
91
91
  return reference
92
92
  end
93
93
 
94
- def validate
94
+ def validate(labels = nil)
95
95
  error = String.new
96
+ warnings = String.new
96
97
 
97
98
  if @name.nil? || @name.empty?
98
99
  error = "A name is required for deal.\n}"
@@ -106,11 +107,15 @@ module GoImport
106
107
  error = "#{error}\n#{@status.status_reference.validate}"
107
108
  end
108
109
 
110
+ if !@status.nil? && !@status.status_reference.nil? && (labels.nil? || (!labels.nil? && !labels.include?(@status.status_reference.label)))
111
+ warnings = "Deal status '#{@status.status_reference.label}' missing, add to settings"
112
+ end
113
+
109
114
  if error.length > 0
110
115
  error = "#{error}\n#{serialize()}"
111
116
  end
112
117
 
113
- return error
118
+ return [error, warnings]
114
119
  end
115
120
 
116
121
 
@@ -168,13 +173,13 @@ module GoImport
168
173
  def value=(value)
169
174
  if value.nil?
170
175
  @value = "0"
171
- elsif value.empty?
176
+ elsif value.respond_to?(:empty?) && value.empty?
172
177
  @value = "0"
173
178
  else
174
179
  # we have had some issues with LIME Easy imports where
175
180
  # the value was in the format "357 000". We need to
176
181
  # remove those spaces.
177
- fixed_value = value.gsub(" ", "")
182
+ fixed_value = value.to_s.gsub(" ", "")
178
183
 
179
184
  # we assume that both , and . are thousand separators
180
185
  # and remove them from the value string. We dont care
@@ -6,6 +6,8 @@ require_relative '../serialize_helper'
6
6
 
7
7
  module GoImport
8
8
  class File
9
+ MAX_FILE_SIZE = 100000000 # 100 Mb
10
+
9
11
  include SerializeHelper
10
12
  attr_accessor :id, :integration_id, :description
11
13
 
@@ -155,7 +157,7 @@ module GoImport
155
157
  zip_file.add(@location_in_zip_file, path_for_project)
156
158
  end
157
159
 
158
- def validate(ignore_missing_files = false)
160
+ def validate(ignore_invalid_files = false)
159
161
  error = String.new
160
162
  warning = String.new
161
163
 
@@ -165,12 +167,15 @@ module GoImport
165
167
 
166
168
  if @path.nil? || @path.empty?
167
169
  error = "Path is required for file.\n"
168
- else
169
- if !ignore_missing_files && !::File.exists?(path_for_project())
170
+ elsif !ignore_invalid_files
171
+ if !::File.exists?(path_for_project())
170
172
  error = "#{error}Can't find file with name '#{@name}' and original path '#{@path}' at '#{path_for_project()}'."
173
+ elsif ::File.size(path_for_project()) > MAX_FILE_SIZE
174
+ error = "#{error}File '#{@name}' is bigger than #{MAX_FILE_SIZE} bytes."
171
175
  end
172
176
  end
173
177
 
178
+
174
179
  if @created_by_reference.nil?
175
180
  error = "#{error}Created_by is required for file (#{@name}).\n"
176
181
  end
@@ -90,7 +90,6 @@ module GoImport
90
90
  else
91
91
  raise InvalidNoteClassificationError, classification
92
92
  end
93
-
94
93
  end
95
94
 
96
95
  def text=(text)
@@ -208,6 +208,10 @@ module GoImport
208
208
  raise AlreadyAddedError, "Already added a note with integration_id #{note.integration_id}"
209
209
  end
210
210
 
211
+ if note.created_by.nil?
212
+ note.created_by = @import_coworker
213
+ end
214
+
211
215
  @notes.push(note)
212
216
 
213
217
  return note
@@ -306,22 +310,26 @@ module GoImport
306
310
  return error.strip
307
311
  end
308
312
 
309
- def validate(ignore_missing_files = false)
310
- error = String.new
313
+ def validate(ignore_invalid_files = false)
314
+ errors = String.new
315
+ warnings = String.new
311
316
 
312
317
  @organizations.each do |o|
313
318
  validation_message = o.validate()
314
319
 
315
320
  if !validation_message.empty?
316
- error = "#{error}\n#{validation_message}"
321
+ errors = "#{errors}\n#{validation_message}"
317
322
  end
318
323
  end
319
324
 
320
325
  @deals.each do |deal|
321
- validation_message = deal.validate
326
+ error, warning = deal.validate @settings.deal.statuses.map {|status| status.label}
322
327
 
323
- if !validation_message.empty?
324
- error = "#{error}\n#{validation_message}"
328
+ if !error.empty?
329
+ errors = "#{errors}\n#{error}"
330
+ end
331
+ if !warning.empty?
332
+ warnings = "#{warnings}\n#{warning}"
325
333
  end
326
334
  end
327
335
 
@@ -329,25 +337,25 @@ module GoImport
329
337
  validation_message = note.validate
330
338
 
331
339
  if !validation_message.empty?
332
- error = "#{error}\n#{validation_message}"
340
+ errors = "#{errors}\n#{validation_message}"
333
341
  end
334
342
  end
335
343
 
336
344
  @documents.links.each do |link|
337
345
  validation_message = link.validate
338
346
  if !validation_message.empty?
339
- error = "#{error}\n#{validation_message}"
347
+ errors = "#{errors}\n#{validation_message}"
340
348
  end
341
349
  end
342
350
 
343
351
  @documents.files.each do |file|
344
- validation_message = file.validate(ignore_missing_files)
352
+ validation_message = file.validate(ignore_invalid_files)
345
353
  if !validation_message.empty?
346
- error = "#{error}\n#{validation_message}"
354
+ errors = "#{errors}\n#{validation_message}"
347
355
  end
348
356
  end
349
357
 
350
- return error.strip
358
+ return [errors.strip, warnings.strip]
351
359
  end
352
360
 
353
361
  # @!visibility private
@@ -0,0 +1,14 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+ # Ignore built gems
10
+ /*.gem
11
+ # Ignore all logfiles and tempfiles.
12
+ /tmp
13
+ /spec/tmp
14
+ pkg
@@ -0,0 +1 @@
1
+ This source converts a LIME Pro "Core" database to LIME Go.