go_import 3.0.40 → 3.0.42

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59427aef6763d25193bcb19a34b834207e0a1afa
4
- data.tar.gz: 171379596422ffb7b8bf31d2d071ebb05682db26
3
+ metadata.gz: c51550ffff27ad4fe7f57413acf77764bfd98c9c
4
+ data.tar.gz: 7aed552fb4339fce5e9419ec9153d60d6add44aa
5
5
  SHA512:
6
- metadata.gz: b8e6aa91dec72dbffe0bcf9d430b78a51c28208c60758a3dd85f959dce032b50d7f0f95402c4996eec20cace636173d7010a23909df1008c03ee983a9c33cfaf
7
- data.tar.gz: f3d1e0faa54a918fce9136b5247f8af2dd6d9d6b06dffb895d9d3550d87cc24a9ba92a069f59f7b7e9ce125a5ccf3959dd468f5cb94b741b9a8cb264469fcc9f
6
+ metadata.gz: 8d7028dc367f5d84904c731018c0d77d2951d7267649926e0066584ef0560f43fd797634a8c6f634d6c5de7e983d1dcb1bb3e4860d85040b077eb2de5e39cd35
7
+ data.tar.gz: b3bb492a053c4dee863714424af4d763d1a0c6c2d907416b6f7190356c6550b70d4842b10e4ba82ece600254aa66865b12ac88207b44d38c5541067d6974f427
data/bin/go-import CHANGED
@@ -76,7 +76,7 @@ class GoImportCommandLine < Thor
76
76
  $stdout = File.new(options.log_to_file == "log_to_file" ? "go-import.log" : options.log_to_file, 'w')
77
77
  $stdout.sync = true
78
78
  end
79
- max_file_size = options.max_file_size.nil? ? GoImport::File::DEFAULT_MAX_FILE_SIZE : options.max_file_size
79
+ max_file_size = options.max_file_size.nil? ? GoImport::File::DEFAULT_MAX_FILE_SIZE : options.max_file_size
80
80
 
81
81
  if !is_valid_goimport_project?
82
82
  return
@@ -102,6 +102,7 @@ class GoImportCommandLine < Thor
102
102
  if options.ignore_invalid_files && model.documents.files.length > 0
103
103
  log_and_remove_invalid_files model, max_file_size
104
104
  end
105
+ model.report_rootmodel_status()
105
106
 
106
107
  puts "Starting sharding of model..."
107
108
  sharder = GoImport::ShardHelper.new(options.shard_size)
@@ -111,14 +112,14 @@ class GoImportCommandLine < Thor
111
112
  puts "Import is large and will be broken into #{models_to_serialize.length} files"
112
113
  end
113
114
 
114
- models_to_serialize.each_with_index do |model, i|
115
+ models_to_serialize.each_with_index do |model, i|
115
116
  go_data_zip = options.output.nil? == true ? "go" : options.output
116
117
  go_data_zip += "_#{i}.zip"
117
118
  go_files = options.output_documents.nil? == true ? nil : ::File.basename(options.output_documents,File.extname(options.output_documents))
118
119
  model.save_to_zip(go_data_zip, go_files)
119
120
  puts "Source has been been converted into '#{go_data_zip}'."
120
121
  puts " - and files into '#{go_files}.zip'." if !go_files.nil?
121
- if !warnings_msg.empty?
122
+ if !warnings_msg.empty?
122
123
  puts "WARNINGS: "
123
124
  puts warnings_msg
124
125
  end
@@ -205,4 +206,3 @@ class GoImportCommandLine < Thor
205
206
  end
206
207
 
207
208
  GoImportCommandLine.start(ARGV)
208
-
@@ -37,10 +37,10 @@ module GoImport
37
37
  end
38
38
  end
39
39
  end
40
-
40
+
41
41
  class Organization < CanBecomeImmutable
42
42
  include SerializeHelper, ModelHasCustomFields, ModelHasTags
43
-
43
+
44
44
  immutable_accessor :id
45
45
  immutable_accessor :integration_id
46
46
  immutable_accessor :name
@@ -134,6 +134,7 @@ module GoImport
134
134
  def add_employee(val)
135
135
  @employees = [] if @employees == nil
136
136
  person = if val.is_a? Person then val else Person.new(val) end
137
+ person.set_organization_reference = self
137
138
  @employees.push(person)
138
139
 
139
140
  # *** TODO:
@@ -144,9 +145,9 @@ module GoImport
144
145
  # person after is has been added to the organization. We
145
146
  # must update the sources before we can set the person
146
147
  # immutable here.
147
-
148
+
148
149
  #person.set_is_immutable
149
-
150
+
150
151
  return person
151
152
  end
152
153
 
@@ -164,7 +165,7 @@ module GoImport
164
165
  # otherwise an InvalidRelationError error will be thrown.
165
166
  def relation=(relation)
166
167
  raise_if_immutable
167
-
168
+
168
169
  if relation == Relation::NoRelation || relation == Relation::WorkingOnIt ||
169
170
  relation == Relation::IsACustomer || relation == Relation::WasACustomer || relation == Relation::BeenInTouch
170
171
  @relation = relation
@@ -174,10 +175,10 @@ module GoImport
174
175
  raise InvalidRelationError
175
176
  end
176
177
  end
177
-
178
+
178
179
  def relation_last_modified=(date)
179
180
  raise_if_immutable
180
-
181
+
181
182
  begin
182
183
  @relation_last_modified = @relation != Relation::NoRelation ? Date.parse(date).strftime("%Y-%m-%d") : nil
183
184
  rescue
@@ -28,11 +28,11 @@ module GoImport
28
28
  end
29
29
  end
30
30
 
31
- class Person < CanBecomeImmutable
31
+ class Person < CanBecomeImmutable
32
32
  include SerializeHelper, ModelHasCustomFields, ModelHasTags
33
33
 
34
34
  immutable_accessor :id
35
- immutable_accessor :integration_id
35
+ immutable_accessor :integration_id
36
36
  immutable_accessor :first_name
37
37
  immutable_accessor :last_name
38
38
  immutable_accessor :direct_phone_number
@@ -60,7 +60,7 @@ module GoImport
60
60
  set_tag 'Import'
61
61
  end
62
62
 
63
- def organization=(org)
63
+ def set_organization_reference=(org)
64
64
  @organization = OrganizationReference.from_organization(org)
65
65
  end
66
66
 
@@ -22,7 +22,7 @@ module GoImport
22
22
  # default.
23
23
  attr_accessor :configuration
24
24
 
25
- attr_reader :documents
25
+ attr_reader :documents, :persons
26
26
 
27
27
  def serialize_variables
28
28
  [
@@ -57,6 +57,10 @@ module GoImport
57
57
  configure
58
58
  end
59
59
 
60
+ def persons
61
+ return @organizations.collect{|k, o| o.employees}.flatten.compact
62
+ end
63
+
60
64
  # Adds the specifed coworker object to the model.
61
65
 
62
66
  # @example Add a coworker from a new coworker
@@ -79,7 +83,7 @@ module GoImport
79
83
  raise IntegrationIdIsRequiredError, "An integration id is required for a coworker."
80
84
  end
81
85
 
82
- if find_coworker_by_integration_id(coworker.integration_id) != nil
86
+ if find_coworker_by_integration_id(coworker.integration_id, false) != nil
83
87
  raise AlreadyAddedError, "Already added a coworker with integration_id #{coworker.integration_id}"
84
88
  end
85
89
 
@@ -103,12 +107,12 @@ module GoImport
103
107
  if !organization.is_a?(Organization)
104
108
  raise ArgumentError.new("Expected an organization")
105
109
  end
106
-
110
+
107
111
  if organization.integration_id.nil? || organization.integration_id.length == 0
108
112
  raise IntegrationIdIsRequiredError, "An integration id is required for an organization."
109
113
  end
110
114
 
111
- if find_organization_by_integration_id(organization.integration_id) != nil
115
+ if find_organization_by_integration_id(organization.integration_id, false) != nil
112
116
  raise AlreadyAddedError, "Already added an organization with integration_id #{organization.integration_id}"
113
117
  end
114
118
 
@@ -137,10 +141,10 @@ module GoImport
137
141
  raise IntegrationIdIsRequiredError, "An integration id is required for a deal."
138
142
  end
139
143
 
140
- if find_deal_by_integration_id(deal.integration_id) != nil
144
+ if find_deal_by_integration_id(deal.integration_id, false) != nil
141
145
  raise AlreadyAddedError, "Already added a deal with integration_id #{deal.integration_id}"
142
146
  end
143
-
147
+
144
148
  if !configuration[:allow_deals_without_responsible] && deal.responsible_coworker.nil?
145
149
  deal.responsible_coworker = @import_coworker
146
150
  end
@@ -158,6 +162,13 @@ module GoImport
158
162
  configuration[:allow_deals_without_responsible] =
159
163
  config_value.downcase == "true" || config_value == "1"
160
164
  end
165
+
166
+ if defined?(REPORT_RESULT)
167
+ config_value = REPORT_RESULT.to_s
168
+
169
+ configuration[:report_result] =
170
+ config_value.downcase == "true" || config_value == "1"
171
+ end
161
172
  end
162
173
 
163
174
  # Adds the specifed note object to the model.
@@ -182,15 +193,15 @@ module GoImport
182
193
  if note.integration_id.nil? || note.integration_id.length == 0
183
194
  note.integration_id = @notes.length.to_s
184
195
  end
185
-
186
- if find_note_by_integration_id(note.integration_id) != nil
196
+
197
+ if find_note_by_integration_id(note.integration_id, false) != nil
187
198
  raise AlreadyAddedError, "Already added a note with integration_id #{note.integration_id}"
188
199
  end
189
200
 
190
201
  if note.created_by.nil?
191
202
  note.created_by = @import_coworker
192
203
  end
193
-
204
+
194
205
  @notes[note.integration_id] = note
195
206
  note.set_is_immutable
196
207
 
@@ -209,35 +220,40 @@ module GoImport
209
220
  return @documents.add_file(file)
210
221
  end
211
222
 
212
- def find_coworker_by_integration_id(integration_id)
223
+ def find_coworker_by_integration_id(integration_id, report_result=!!configuration[:report_result])
213
224
  if @coworkers.has_key?(integration_id)
214
225
  return @coworkers[integration_id]
215
226
  else
227
+ report_failed_to_find_object("coworker", ":#{integration_id}") if report_result
216
228
  return nil
217
229
  end
218
230
  end
219
231
 
220
- def find_organization_by_integration_id(integration_id)
232
+ def find_organization_by_integration_id(integration_id, report_result=!!configuration[:report_result])
221
233
  if @organizations.has_key?(integration_id)
222
234
  return @organizations[integration_id]
223
235
  else
236
+ report_failed_to_find_object("organization", ":#{integration_id}") if report_result
224
237
  return nil
225
238
  end
226
239
 
227
240
  end
228
241
 
229
- def find_person_by_integration_id(integration_id)
242
+ def find_person_by_integration_id(integration_id, report_result=!!configuration[:report_result])
230
243
  return nil if @organizations.nil?
231
244
  @organizations.each do |key, organization|
232
245
  person = organization.find_employee_by_integration_id(integration_id)
233
246
  return person if person
234
247
  end
248
+ report_failed_to_find_object("person", ":#{integration_id}") if report_result
249
+ return nil
235
250
  end
236
251
 
237
- def find_note_by_integration_id(integration_id)
252
+ def find_note_by_integration_id(integration_id, report_result=!!configuration[:report_result])
238
253
  if @notes.has_key?(integration_id)
239
254
  return @notes[integration_id]
240
255
  else
256
+ report_failed_to_find_object("note", ":#{integration_id}") if report_result
241
257
  return nil
242
258
  end
243
259
  end
@@ -249,18 +265,122 @@ module GoImport
249
265
  deals = @deals.values.select do |deal|
250
266
  !deal.customer.nil? && deal.customer.integration_id == organization.integration_id
251
267
  end
252
-
253
268
  return deals
254
269
  end
255
270
 
256
- def find_deal_by_integration_id(integration_id)
271
+ def find_deal_by_integration_id(integration_id, report_result=!!configuration[:report_result])
257
272
  if @deals.has_key?(integration_id)
258
273
  return @deals[integration_id]
259
274
  else
275
+ report_failed_to_find_object("deal", ":#{integration_id}") if report_result
260
276
  return nil
261
277
  end
262
278
  end
263
279
 
280
+ # Finds a organization based on one of its property.
281
+ # Returns the first found matching organization
282
+ # Method is much slower then using find_organization_by_integration_id
283
+ # @example Finds a organization on its name
284
+ # rm.find_organization {|org| org.name == "Lundalogik" }
285
+ def find_organization(report_result=!!configuration[:report_result], &block)
286
+ result = find(@organizations.values.flatten, &block)
287
+ report_failed_to_find_object("organization") if result.nil? and report_result
288
+ return result
289
+ end
290
+
291
+ # Finds organizations based on one of their property.
292
+ # Returns all matching organizations
293
+ # @example Selects organizations on their names
294
+ # rm.select_organizations {|org| org.name == "Lundalogik" }
295
+ def select_organizations(report_result=!!configuration[:report_result], &block)
296
+ result = select(@organizations.values.flatten, &block)
297
+ report_failed_to_find_object("organization") if result.empty? and report_result
298
+ return result
299
+ end
300
+
301
+ # Finds a person based on one of its property.
302
+ # Returns the first found matching person
303
+ # @example Finds a person on its name
304
+ # rm.find_person {|person| person.first_name == "Kalle" }
305
+ def find_person(report_result=!!configuration[:report_result], &block)
306
+ result = find(persons, &block)
307
+ report_failed_to_find_object("person") if result.nil? and report_result
308
+ return result
309
+ end
310
+
311
+ # Finds persons based on one of their property.
312
+ # Returns all matching persons
313
+ # @example Selects persons on their names
314
+ # rm.select_person {|p| p.first_name == "Kalle" }
315
+ def select_persons(report_result=!!configuration[:report_result], &block)
316
+ result = select(persons, &block)
317
+ report_failed_to_find_object("person") if result.empty? and report_result
318
+ return result
319
+ end
320
+
321
+ # Finds a deal based on one of its property.
322
+ # Returns the first found matching deal
323
+ # Method is much slower then using find_deal_by_integration_id
324
+ # @example Finds a deal on its name
325
+ # rm.find_deal {|deal| deal.value == 120000 }
326
+ def find_deal(report_result=!!configuration[:report_result], &block)
327
+ result = find(@deals.values.flatten, &block)
328
+ report_failed_to_find_object("person") if result.nil? and report_result
329
+ return result
330
+ end
331
+
332
+ # Finds deals based on one of their property.
333
+ # Returns all matching deals
334
+ # @example Selects deals on their names
335
+ # rm.select_deals {|deal| deal.name == "Big Deal" }
336
+ def select_deals(report_result=!!configuration[:report_result], &block)
337
+ result = select(@deals.values.flatten, &block)
338
+ report_failed_to_find_object("deal") if result.empty? and report_result
339
+ return result
340
+ end
341
+
342
+ # Finds a coworker based on one of its property.
343
+ # Returns the first found matching coworker
344
+ # @example Finds a coworker on its name
345
+ # rm.find_coworker {|coworker| coworker.email == "kalle@kula.se" }
346
+ def find_coworker(report_result=!!configuration[:report_result], &block)
347
+ result = find(@coworkers.values.flatten, &block)
348
+ report_failed_to_find_object("coworker") if result.nil? and report_result
349
+ return result
350
+ end
351
+
352
+ # Finds coworkers based on one of their property.
353
+ # Returns all matching coworkers
354
+ # @example Selects coworkers on their names
355
+ # rm.select_coworkers {|coworker| coworker.email == "kalle@kula.se" }
356
+ def select_coworkers(report_result=!!configuration[:report_result], &block)
357
+ result = select(@coworkers, &block)
358
+ report_failed_to_find_object("coworker") if result.empty? and report_result
359
+ return result
360
+ end
361
+
362
+
363
+ # Finds a note based on one of its property.
364
+ # Returns the first found matching note
365
+ # @example Finds a note on its name
366
+ # rm.find_note {|note| note.text == "hello!" }
367
+ def find_note(report_result=!!configuration[:report_result], &block)
368
+ result = find(@notes.values.flatten, &block)
369
+ report_failed_to_find_object("note") if result.nil? and report_result
370
+ return result
371
+ end
372
+
373
+ # Finds a document based on one of its property.
374
+ # Returns the first found matching document
375
+ # @example Finds a document on its name
376
+ # rm.find_document(:file) {|document| document.name == "Important Tender" }
377
+ def find_document(type, report_result=!!configuration[:report_result], &block)
378
+ result = find(@documents.files, &block) if type == :file
379
+ result = find(@documents.links, &block) if type == :link
380
+ report_failed_to_find_object("document") if result.nil? and report_result
381
+ return result
382
+ end
383
+
264
384
  # Returns a string describing problems with the data. For
265
385
  # instance if integration_id for any entity is not unique.
266
386
  def sanity_check
@@ -377,7 +497,7 @@ module GoImport
377
497
  end
378
498
  serialize_to_file(go_data_file)
379
499
  create_zip(zip_filename, go_data_file, documents.files)
380
-
500
+
381
501
  if !files_filename.nil?
382
502
  go_files_file = Tempfile.new('go-files')
383
503
  puts "Creating go.xml file with documents information..."
@@ -393,7 +513,7 @@ module GoImport
393
513
  ::File.delete files_zip_filename
394
514
  end
395
515
  create_zip(files_zip_filename, go_files_file, documents.files)
396
- end
516
+ end
397
517
  end
398
518
 
399
519
  def create_zip(filename, xml, files)
@@ -436,6 +556,17 @@ module GoImport
436
556
  end
437
557
  end
438
558
 
559
+ def report_rootmodel_status
560
+ #nbr_of_persons = @organizations.collect{|k, o| o.employees}.flatten.compact.length
561
+ nbr_of_documents = @documents.files.length + @documents.links.length
562
+ puts "Rootmodel contains:\n" \
563
+ " Organizations: #{@organizations.length}\n" \
564
+ " Persons: #{persons.length}\n" \
565
+ " Deals: #{@deals.length}\n" \
566
+ " Notes: #{@notes.length}\n" \
567
+ " Documents: #{nbr_of_documents}"
568
+ end
569
+
439
570
  private
440
571
  # returns all items from the object array with duplicate integration ids.
441
572
  # To get all organizations with the same integration_id use
@@ -452,5 +583,33 @@ module GoImport
452
583
  obj.integration_id != nil && !obj.integration_id.empty?
453
584
  end
454
585
  end
586
+
587
+ # Prints a warning text if a find-function returns nil
588
+ def report_failed_to_find_object(object, search_string="")
589
+ c = caller_locations(2).first
590
+ puts "Warning: #{c.label}:#{c.lineno}: Failed to find #{object}#{search_string}"
591
+ end
592
+
593
+ def find(array)
594
+ result = nil
595
+ array.each do |obj|
596
+ if yield(obj)
597
+ result = obj
598
+ break
599
+ end
600
+ end
601
+ return result
602
+ end
603
+
604
+ def select(array)
605
+ result = []
606
+ array.each do |obj|
607
+ if yield(obj)
608
+ result.push obj
609
+ end
610
+ end
611
+ return result
612
+ end
613
+
455
614
  end
456
615
  end
@@ -33,6 +33,7 @@ module GoImport
33
33
  # source = "046 - 270 48 00/ 031-712 44 00"
34
34
  # number1, number2 = GoImport::PhoneHelper.parse_numbers(source, '/')
35
35
  def self.parse_numbers(number_string, delimiters = ',', strict_mode = false)
36
+ return nil if number_string.nil?
36
37
  numbers = []
37
38
 
38
39
  if delimiters.is_a?(Array)
@@ -1,17 +1,17 @@
1
1
  module GoImport
2
2
  class ShardHelper
3
-
3
+
4
4
  attr_accessor :shards, :current_shard_count, :current_shard
5
-
5
+
6
6
  def initialize(shard_size = nil)
7
7
  @shard_size = shard_size || 25000
8
8
  setup()
9
9
  end
10
10
 
11
11
  def shard_model(model)
12
- @current_shard.configuration = model.configuration
12
+ @current_shard.settings = model.settings
13
13
 
14
- model.coworkers.each{ |key, coworker|
14
+ model.coworkers.each{ |key, coworker|
15
15
  if coworker.integration_id != "import"
16
16
  add_coworker(coworker)
17
17
  end
@@ -61,7 +61,7 @@ module GoImport
61
61
  @current_shard_count += org.employees.length
62
62
  end
63
63
  @current_shard.add_organization(org)
64
- @current_shard_count += 1
64
+ @current_shard_count += 1
65
65
  end
66
66
 
67
67
  private
@@ -74,16 +74,16 @@ module GoImport
74
74
  def add_file(file)
75
75
  check_or_create_new_chard()
76
76
  @current_shard.add_file(file)
77
- @current_shard_count += 1
77
+ @current_shard_count += 1
78
78
  end
79
79
 
80
80
  private
81
81
  def add_link(link)
82
82
  check_or_create_new_chard()
83
83
  @current_shard.add_link(link)
84
- @current_shard_count += 1
84
+ @current_shard_count += 1
85
85
  end
86
-
86
+
87
87
  private
88
88
  def check_or_create_new_chard()
89
89
  if @current_shard_count > @shard_size