move-to-go 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +7 -0
  2. data/bin/move-to-go +210 -0
  3. data/lib/move-to-go/can_become_immutable.rb +29 -0
  4. data/lib/move-to-go/csv_helper.rb +47 -0
  5. data/lib/move-to-go/email_helper.rb +14 -0
  6. data/lib/move-to-go/errors.rb +31 -0
  7. data/lib/move-to-go/excel_helper.rb +10 -0
  8. data/lib/move-to-go/global_phone.json +6571 -0
  9. data/lib/move-to-go/model/address.rb +63 -0
  10. data/lib/move-to-go/model/class_settings.rb +50 -0
  11. data/lib/move-to-go/model/clientvisit.rb +10 -0
  12. data/lib/move-to-go/model/comment.rb +10 -0
  13. data/lib/move-to-go/model/coworker.rb +82 -0
  14. data/lib/move-to-go/model/coworker_reference.rb +33 -0
  15. data/lib/move-to-go/model/customfield.rb +87 -0
  16. data/lib/move-to-go/model/deal.rb +216 -0
  17. data/lib/move-to-go/model/deal_class_settings.rb +97 -0
  18. data/lib/move-to-go/model/deal_state.rb +15 -0
  19. data/lib/move-to-go/model/deal_status.rb +23 -0
  20. data/lib/move-to-go/model/deal_status_reference.rb +47 -0
  21. data/lib/move-to-go/model/deal_status_setting.rb +49 -0
  22. data/lib/move-to-go/model/documents.rb +76 -0
  23. data/lib/move-to-go/model/file.rb +193 -0
  24. data/lib/move-to-go/model/history.rb +148 -0
  25. data/lib/move-to-go/model/history_classification.rb +26 -0
  26. data/lib/move-to-go/model/link.rb +82 -0
  27. data/lib/move-to-go/model/organization.rb +250 -0
  28. data/lib/move-to-go/model/person.rb +164 -0
  29. data/lib/move-to-go/model/referencetosource.rb +58 -0
  30. data/lib/move-to-go/model/relation.rb +23 -0
  31. data/lib/move-to-go/model/rootmodel.rb +663 -0
  32. data/lib/move-to-go/model/salescall.rb +10 -0
  33. data/lib/move-to-go/model/settings.rb +61 -0
  34. data/lib/move-to-go/model/tag.rb +35 -0
  35. data/lib/move-to-go/model/talkedto.rb +10 -0
  36. data/lib/move-to-go/model/triedtoreach.rb +10 -0
  37. data/lib/move-to-go/model_helpers.rb +97 -0
  38. data/lib/move-to-go/phone_helper.rb +75 -0
  39. data/lib/move-to-go/roo_helper.rb +82 -0
  40. data/lib/move-to-go/serialize_helper.rb +199 -0
  41. data/lib/move-to-go/shard_helper.rb +96 -0
  42. data/lib/move-to-go/source.rb +108 -0
  43. data/lib/move-to-go/templating.rb +52 -0
  44. data/lib/move-to-go.rb +20 -0
  45. data/sources/VISMA/.gitignore +14 -0
  46. data/sources/VISMA/.move-to-go/readme.txt +1 -0
  47. data/sources/VISMA/.move-to-go/runner.rb +89 -0
  48. data/sources/VISMA/Database/KONTAKT.DBF +0 -0
  49. data/sources/VISMA/Database/KUND.DBF +0 -0
  50. data/sources/VISMA/Gemfile +5 -0
  51. data/sources/VISMA/converter.rb +120 -0
  52. data/sources/base-crm/.move-to-go/runner.rb +235 -0
  53. data/sources/base-crm/Gemfile +5 -0
  54. data/sources/base-crm/README.md +9 -0
  55. data/sources/base-crm/converter.rb +56 -0
  56. data/sources/base-crm/data/contacts.csv +13 -0
  57. data/sources/base-crm/data/coworkers.csv +3 -0
  58. data/sources/base-crm/data/deals.csv +5 -0
  59. data/sources/base-crm/data/histories.csv +6 -0
  60. data/sources/base-crm/data/leads.csv +4 -0
  61. data/sources/base-crm/data/tasks.csv +5 -0
  62. data/sources/csv/.gitignore +14 -0
  63. data/sources/csv/.move-to-go/readme.txt +1 -0
  64. data/sources/csv/.move-to-go/runner.rb +65 -0
  65. data/sources/csv/Gemfile +5 -0
  66. data/sources/csv/converter.rb +218 -0
  67. data/sources/csv/data/coworkers.csv +2 -0
  68. data/sources/csv/data/deals.csv +2 -0
  69. data/sources/csv/data/organizations.csv +2 -0
  70. data/sources/csv/data/persons.csv +2 -0
  71. data/sources/custom/.gitignore +14 -0
  72. data/sources/custom/.move-to-go/readme.txt +1 -0
  73. data/sources/custom/.move-to-go/runner.rb +30 -0
  74. data/sources/custom/Gemfile +4 -0
  75. data/sources/custom/converter.rb +45 -0
  76. data/sources/excel/.gitignore +14 -0
  77. data/sources/excel/.move-to-go/readme.txt +3 -0
  78. data/sources/excel/.move-to-go/runner.rb +140 -0
  79. data/sources/excel/Gemfile +7 -0
  80. data/sources/excel/converter.rb +188 -0
  81. data/sources/excel/files/avtal.docx +0 -0
  82. data/sources/excel/files/more/avtal.docx +0 -0
  83. data/sources/excel/files/more/offert-2.pdf +0 -0
  84. data/sources/excel/files/offert-2.docx +0 -0
  85. data/sources/excel/files/offert.docx +0 -0
  86. data/sources/excel/sample-data.xlsx +0 -0
  87. data/sources/excel-basic/.gitignore +14 -0
  88. data/sources/excel-basic/.move-to-go/readme.txt +3 -0
  89. data/sources/excel-basic/.move-to-go/runner.rb +139 -0
  90. data/sources/excel-basic/Exempelfil.xlsx +0 -0
  91. data/sources/excel-basic/Gemfile +6 -0
  92. data/sources/excel-basic/converter.rb +175 -0
  93. data/sources/excel-basic/files/avtal.docx +0 -0
  94. data/sources/excel-basic/files/more/avtal.docx +0 -0
  95. data/sources/excel-basic/files/more/offert-2.pdf +0 -0
  96. data/sources/excel-basic/files/offert-2.docx +0 -0
  97. data/sources/excel-basic/files/offert.docx +0 -0
  98. data/sources/lime-crm-basic/.gitignore +14 -0
  99. data/sources/lime-crm-basic/.move-to-go/readme.txt +1 -0
  100. data/sources/lime-crm-basic/.move-to-go/runner.rb +524 -0
  101. data/sources/lime-crm-basic/Gemfile +6 -0
  102. data/sources/lime-crm-basic/converter.rb +396 -0
  103. data/sources/lime-easy/.gitignore +14 -0
  104. data/sources/lime-easy/.move-to-go/readme.txt +1 -0
  105. data/sources/lime-easy/.move-to-go/runner.rb +348 -0
  106. data/sources/lime-easy/Export/readme.txt +6 -0
  107. data/sources/lime-easy/Gemfile +5 -0
  108. data/sources/lime-easy/converter.rb +362 -0
  109. data/sources/salesforce/.gitignore +14 -0
  110. data/sources/salesforce/.move-to-go/readme.txt +1 -0
  111. data/sources/salesforce/.move-to-go/runner.rb +404 -0
  112. data/sources/salesforce/Gemfile +6 -0
  113. data/sources/salesforce/Gemfile.lock +48 -0
  114. data/sources/salesforce/converter.rb +113 -0
  115. data/sources/salesforce/export/readme.txt +3 -0
  116. data/spec/address_spec.rb +49 -0
  117. data/spec/class_settings_spec.rb +37 -0
  118. data/spec/coworker_spec.rb +94 -0
  119. data/spec/custom_field_spec.rb +22 -0
  120. data/spec/deal_class_settings_spec.rb +116 -0
  121. data/spec/deal_spec.rb +232 -0
  122. data/spec/deal_status_reference_spec.rb +17 -0
  123. data/spec/documents_spec.rb +64 -0
  124. data/spec/file_spec.rb +178 -0
  125. data/spec/helpers/csv_helper_spec.rb +45 -0
  126. data/spec/helpers/email_helper_spec.rb +37 -0
  127. data/spec/helpers/phone_helper_spec.rb +119 -0
  128. data/spec/helpers/roo_helper_spec.rb +10 -0
  129. data/spec/helpers/serialize_helper_spec.rb +253 -0
  130. data/spec/helpers/shard_helper_spec.rb +141 -0
  131. data/spec/helpers/xsd_validate_spec.rb +57 -0
  132. data/spec/history_spec.rb +150 -0
  133. data/spec/link_spec.rb +107 -0
  134. data/spec/organization_spec.rb +221 -0
  135. data/spec/person_spec.rb +129 -0
  136. data/spec/rootmodel_spec.rb +993 -0
  137. data/spec/spec_helper.rb +30 -0
  138. metadata +362 -0
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ module MoveToGo
3
+ class Settings
4
+ include SerializeHelper
5
+ attr_reader :organization, :person, :deal
6
+
7
+ # @example Add custom fields available for organization
8
+ # rootmodel.settings.with_organization do |organization_settings|
9
+ # organization_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
10
+ # organization_settings.set_custom_field({:integration_id=>"yield_quota", :title=>"Yield quota"})
11
+ # end
12
+ # @see ClassSettings
13
+ # @see CustomField
14
+ # @see RootModel
15
+ def with_organization
16
+ @organization = ClassSettings.new if @organization ==nil
17
+ yield @organization
18
+ end
19
+
20
+ # @example Add custom fields available for person
21
+ # rootmodel.settings.with_person do |person_settings|
22
+ # person_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
23
+ # end
24
+ # @see ClassSettings
25
+ # @see CustomField
26
+ # @see RootModel
27
+ def with_person
28
+ @person = ClassSettings.new if @person ==nil
29
+ yield @person
30
+ end
31
+
32
+ # @example Add custom fields available for deal
33
+ # rootmodel.settings.with_deal do |deal_settings|
34
+ # deal_settings.set_custom_field({:integration_id=>"link_to_bi_system", :title=>"Link to BI system"})
35
+ # end
36
+ # @see ClassSettings
37
+ # @see CustomField
38
+ # @see RootModel
39
+ def with_deal
40
+ @deal = DealClassSettings.new if @deal ==nil
41
+ yield @deal
42
+ end
43
+
44
+ def initialize(opt = nil)
45
+ if opt != nil
46
+ serialize_variables.each do |myattr|
47
+ val = opt[myattr[:id]]
48
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
49
+ end
50
+ end
51
+ end
52
+
53
+ def serialize_variables
54
+ [:organization, :person, :deal].map {|p| {:id => p, :type => :class_settings} }
55
+ end
56
+
57
+ def serialize_name
58
+ "Settings"
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module MoveToGo
4
+ class Tag
5
+ def serialize_name
6
+ "Tag"
7
+ end
8
+
9
+ attr_accessor :value
10
+
11
+ def initialize(val=nil)
12
+ if val
13
+ @value = val
14
+ end
15
+ end
16
+
17
+ # @!visibility private
18
+ def to_rexml(elem)
19
+ element_name = serialize_name
20
+ elem.add_element(element_name).text = @value.to_s.encode('utf-8')
21
+ end
22
+
23
+ def to_s
24
+ return "tag: '#{@value}'"
25
+ end
26
+
27
+ def ==(other)
28
+ if other.respond_to?(:value)
29
+ return @value == other.value
30
+ else
31
+ return false
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'history'
2
+ module MoveToGo
3
+ class TalkedTo < History
4
+ def initialize(opt = nil)
5
+ super(opt)
6
+
7
+ @classification = HistoryClassification::TalkedTo
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'history'
2
+ module MoveToGo
3
+ class TriedToReach < History
4
+ def initialize(opt = nil)
5
+ super(opt)
6
+
7
+ @classification = HistoryClassification::TriedToReach
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,97 @@
1
+ module MoveToGo
2
+ module ModelHasCustomFields
3
+ # @example
4
+ # value = row['business_value_partner_info']
5
+ # obj.set_custom_value("external_url", "https://www.somecompany.com")
6
+ def set_custom_value(integration_id, value)
7
+ @custom_values = [] if @custom_values == nil
8
+
9
+ if value.nil?
10
+ return
11
+ end
12
+
13
+ valueAsString = value.to_s
14
+ if valueAsString.length == 0
15
+ return
16
+ end
17
+
18
+ field = CustomFieldReference.new({:integration_id => integration_id})
19
+ custom_value = CustomValue.new
20
+ custom_value.value = valueAsString
21
+ custom_value.field = field
22
+
23
+ index = @custom_values.find_index do |custom_value|
24
+ custom_value.field.same_as?(field)
25
+ end
26
+
27
+ if index
28
+ @custom_values.delete_at index
29
+ end
30
+
31
+ @custom_values.push custom_value
32
+ return custom_value
33
+ end
34
+ end
35
+
36
+ module ImmutableModel
37
+ @is_immutable = false
38
+ def self.immutable_accessor(name)
39
+ define_method(name) do
40
+ return instance_variable_get("@#{name}")
41
+ end
42
+
43
+ define_method("#{name}=") do |value|
44
+ raise_if_immutable
45
+ instance_variable_set("@#{name}", value)
46
+ end
47
+ end
48
+
49
+ def raise_if_immutable
50
+ if @is_immutable
51
+ raise ObjectIsImmutableError
52
+ end
53
+ end
54
+
55
+ def is_immutable()
56
+ @is_immutable = true
57
+ end
58
+ end
59
+
60
+ module ModelWithIntegrationIdSameAs
61
+ # check if other is same as regarding integration_id or id
62
+ def same_as?(other)
63
+ if @integration_id != nil && @integration_id == other.integration_id
64
+ return true
65
+ end
66
+ if @id != nil && @id == other.id
67
+ return true
68
+ end
69
+ return false
70
+ end
71
+ end
72
+
73
+ module ModelHasTags
74
+ attr_reader :tags
75
+
76
+ # @example
77
+ # obj.set_tag("partner")
78
+ def set_tag(str)
79
+ if str.nil?
80
+ return
81
+ end
82
+
83
+ if !str.is_a?(String)
84
+ return
85
+ end
86
+
87
+ if str.length == 0
88
+ return
89
+ end
90
+
91
+ @tags = [] if @tags == nil
92
+ if ! @tags.any? {|tag| tag.value == str }
93
+ @tags.push(Tag.new(str))
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,75 @@
1
+ require 'global_phone'
2
+
3
+ module MoveToGo
4
+ # The PhoneHelper helps you parse and format phone number strings
5
+ # into pretty looking numbers.
6
+ class PhoneHelper
7
+ GlobalPhone.db_path = ::File.join(::File.dirname(__FILE__), 'global_phone.json')
8
+ GlobalPhone.default_territory_name = :se
9
+
10
+ # Sets the country code used during parsning. The default is
11
+ # swedish (:se) and if you are parsing swedish numbers you
12
+ # dont need to set the country code.
13
+ def self.set_country_code(country_code)
14
+ GlobalPhone.default_territory_name = country_code
15
+ end
16
+
17
+ # Parses the specifed number_string and returns only valid
18
+ # numbers.
19
+ # @see parse_numbers
20
+ def self.parse_numbers_strict(number_string, delimiters = ',')
21
+ parse_numbers number_string, delimiters, true
22
+ end
23
+
24
+ # Parses the specified number_string into one or more phone
25
+ # numbers using the specified delimiters. If strict_mode is
26
+ # true only valid numbers are returned, otherwise are invalid
27
+ # numbers returned as found in the number_string.
28
+ #
29
+ # @example Parse a number
30
+ # number = MoveToGo::PhoneHelper.parse_numbers("046 - 270 48 00")
31
+ #
32
+ # @example Parses a string with two numbers and a custom delimiter
33
+ # source = "046 - 270 48 00/ 031-712 44 00"
34
+ # number1, number2 = MoveToGo::PhoneHelper.parse_numbers(source, '/')
35
+ def self.parse_numbers(number_string, delimiters = ',', strict_mode = false)
36
+ return nil if number_string.nil?
37
+ numbers = []
38
+
39
+ if delimiters.is_a?(Array)
40
+ # we have several delimiters, replace all delimiters
41
+ # in the number_string with the first delimiter
42
+ delimiters.each do |del|
43
+ number_string = number_string.sub(del, delimiters[0])
44
+ end
45
+ delimiter = delimiters[0]
46
+ elsif delimiters.is_a?(String)
47
+ delimiter = delimiters
48
+ else
49
+ raise "delimiters should be either a string or and array of strings"
50
+ end
51
+
52
+ number_string.split(delimiter).each do |possible_number|
53
+ if !possible_number.empty?
54
+ number = GlobalPhone.parse([possible_number])
55
+
56
+ if !number.nil? && number.valid?
57
+ numbers.push number.to_s
58
+ else
59
+ if !strict_mode
60
+ numbers.push possible_number
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ if numbers.length == 0
67
+ return ""
68
+ elsif numbers.length == 1
69
+ return numbers[0]
70
+ else
71
+ return numbers
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,82 @@
1
+ require "csv"
2
+ module MoveToGo
3
+ # @example transform xlsx file into rows
4
+ # organizations_path = File.join(File.dirname(__FILE__), 'organizations.xlsx') # same path as this file
5
+ # rows = MoveToGo::RooHelper.new(Roo::Excelx.new(organizations_path)).rows
6
+ class RooHelper
7
+
8
+ def initialize(data)
9
+ @data = data
10
+ @default_sheet = data.sheets.first
11
+ end
12
+
13
+ # Get rows for the first sheet.
14
+ # The rows are hashes of the first row of cells as header cells and the rest as content.
15
+ # @example If the header 'Name' and the second column contains 'Johan'.
16
+ # MoveToGo::RooHelper.new(Roo::Excelx.new(file_path)).rows
17
+ # # returns:
18
+ # [{'Name'=>'Johan'}]
19
+ def rows
20
+ return rows_for_sheet(@default_sheet)
21
+ end
22
+
23
+ # Returns true if the current workbook has a sheet with the
24
+ # specifed name. This is case sensitive.
25
+ def has_sheet?(name)
26
+ sheet = @data.sheets.find { |s| s.to_s == name}
27
+
28
+ return !sheet.nil?
29
+ end
30
+
31
+ # @example transform xlsx file into rows for the second sheet
32
+ # data = Roo::Excelx.new(organizations_path)
33
+ # rows = MoveToGo::RooHelper.new(data).rows_for_sheet(data.sheets[1])
34
+ def rows_for_sheet(sheet)
35
+ column_headers = {}
36
+ 1.upto(@data.last_column(sheet)) do |col|
37
+ column_headers[col] = @data.cell(1, col, sheet).encode('UTF-8')
38
+ end
39
+
40
+ rs = []
41
+ 2.upto(@data.last_row(sheet)) do |row|
42
+ r = {}
43
+ 1.upto(@data.last_column(sheet)) do |col|
44
+ val = cell_to_csv(row, col, sheet)
45
+ r[column_headers[col]] = val
46
+ end
47
+ rs.push(r)
48
+ end
49
+ return rs
50
+ end
51
+
52
+ def cell_to_csv(row, col, sheet)
53
+ if @data.empty?(row,col,sheet)
54
+ ''
55
+ else
56
+ onecell = @data.cell(row,col,sheet)
57
+ case @data.celltype(row,col,sheet)
58
+ when :string
59
+ unless onecell.empty?
60
+ onecell.encode('UTF-8').strip
61
+ end
62
+ when :float, :percentage
63
+ if onecell == onecell.to_i
64
+ onecell.to_i.to_s
65
+ else
66
+ onecell.to_s
67
+ end
68
+ when :date, :datetime
69
+ onecell.to_s
70
+ when :time
71
+ Roo::Base.integer_to_timestring(onecell)
72
+ when :formula
73
+ onecell.to_s
74
+ when :link
75
+ onecell.to_s
76
+ else
77
+ raise "unhandled celltype #{@data.celltype(row,col,sheet)} for cell at row: #{row}, col: #{col} in sheet #{sheet}"
78
+ end || ""
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,199 @@
1
+ # encoding: utf-8
2
+ require "rexml/document"
3
+
4
+ module MoveToGo
5
+ module SerializeHelper
6
+ def serialize()
7
+ SerializeHelper::serialize(self)
8
+ end
9
+
10
+ def serialize_to_file(file)
11
+ SerializeHelper::serialize_to_file(file, self)
12
+ end
13
+
14
+ # @!visibility private
15
+ def self.serialize_variables_rexml(elem, obj)
16
+ if (obj.respond_to?(:serialize_variables))
17
+ obj.serialize_variables.each do |serialize_variable|
18
+ if serialize_variable[:element_name].nil?
19
+ # Remove the @ and replace a _ with the next
20
+ # letter capitalized. Ie @customer_reference
21
+ # should be CustomerReference
22
+ element_name = serialize_variable[:id].to_s.gsub(/^\@/,'').split('_').map do |m|
23
+ m.capitalize
24
+ end.join('')
25
+ else
26
+ element_name = serialize_variable[:element_name].to_s.split('_').map do |m|
27
+ m.capitalize
28
+ end.join('')
29
+ end
30
+
31
+ raw_var = obj.instance_variable_get("@#{serialize_variable[:id].to_s}")
32
+ if raw_var != nil
33
+ element = elem.add_element(element_name)
34
+ if (raw_var.respond_to?(:serialize_variables))
35
+ SerializeHelper::serialize_variables_rexml(element, raw_var)
36
+ elsif (raw_var.is_a?(Array))
37
+ raw_var.each do |raw_var_elem|
38
+ SerializeHelper::serialize_rexml(element, raw_var_elem)
39
+ end
40
+ elsif (raw_var.is_a?(Hash))
41
+ raw_var.each do |key, raw_var_elem|
42
+ SerializeHelper::serialize_rexml(element, raw_var_elem)
43
+ end
44
+ else
45
+ element.text = raw_var.to_s.encode('UTF-8')
46
+ end
47
+ end
48
+ end
49
+ return
50
+ end
51
+ raise "Do not know how to handle #{obj.class} !!"
52
+ end
53
+
54
+ # @!visibility private
55
+ def self.serialize_rexml(elem, obj)
56
+ if obj.respond_to?(:to_rexml)
57
+ obj.to_rexml(elem)
58
+ elsif (obj.respond_to?(:serialize_variables))
59
+ element_name = obj.serialize_name
60
+ SerializeHelper::serialize_variables_rexml(elem.add_element(element_name), obj)
61
+ else
62
+ elem.text = obj.to_s
63
+ end
64
+ end
65
+
66
+ # @!visibility private
67
+ def self.serialize(obj, indent= 2)
68
+ # indent -1 to avoid indent
69
+ if obj.respond_to?(:to_rexml)
70
+ doc = REXML::Document.new()
71
+ SerializeHelper::serialize_rexml(doc, obj)
72
+ doc.write( xml_str = "" , indent, true)
73
+ xml_str
74
+ elsif (obj.respond_to?(:serialize_variables))
75
+ element_name = obj.serialize_name
76
+ doc = REXML::Document.new()
77
+ SerializeHelper::serialize_variables_rexml(doc.add_element(element_name), obj)
78
+ doc.write( xml_str = "", indent, true)
79
+ xml_str
80
+ else
81
+ obj.to_s.encode(:xml => :text)
82
+ end
83
+ end
84
+
85
+ # @!visibility private
86
+ def self.serialize_to_file(file, obj)
87
+ ::File.open(file, 'w') do |f|
88
+ f.write(SerializeHelper::serialize(obj))
89
+ end
90
+ end
91
+
92
+ # @!visibility private
93
+ def symbol_to_name(symbol)
94
+ symbol.to_s.split('_').join(' ').capitalize
95
+ end
96
+
97
+ # @!visibility private
98
+ def map_symbol_to_row(symbol,type)
99
+ {
100
+ :id => symbol.to_s,
101
+ :name => symbol == :id ? 'Go id' : symbol_to_name(symbol),
102
+ :type =>type
103
+ }
104
+ end
105
+
106
+ # @!visibility private
107
+ def map_to_row(p)
108
+ case p[:type]
109
+ when :string then
110
+ map_symbol_to_row(p[:id],p[:type])
111
+ when :bool then
112
+ map_symbol_to_row(p[:id],p[:type])
113
+ when :date then
114
+ map_symbol_to_row(p[:id],p[:type])
115
+ when :histories then
116
+ {
117
+ :id => p[:id].to_s,
118
+ :name => symbol_to_name(p[:id]),
119
+ :type => p[:type],
120
+ :models => SerializeHelper.get_import_rows(:history)
121
+ }
122
+ when :tags then
123
+ {
124
+ :id => p[:id].to_s,
125
+ :type => p[:type],
126
+ :name => symbol_to_name(p[:id]),
127
+ }
128
+ when :persons then
129
+ {
130
+ :id => p[:id].to_s,
131
+ :type => p[:type],
132
+ :name => symbol_to_name(p[:id]),
133
+ :models => SerializeHelper.get_import_rows(:person)
134
+ }
135
+ when :custom_fields then
136
+ {
137
+ :id => p[:id].to_s,
138
+ :type => p[:type],
139
+ :name => symbol_to_name(p[:id]),
140
+ :models => SerializeHelper.get_import_rows(:custom_field)
141
+ }
142
+ when :custom_values then
143
+ {
144
+ :id => p[:id].to_s,
145
+ :type => p[:type],
146
+ :name => symbol_to_name(p[:id]),
147
+ :models => SerializeHelper.get_import_rows(:custom_value)
148
+ }
149
+ else
150
+ {
151
+ :id => p[:id].to_s,
152
+ :name => symbol_to_name(p[:id]),
153
+ :type => p[:type],
154
+ :model => SerializeHelper.get_import_rows(p[:type])
155
+ }
156
+ end
157
+ end
158
+
159
+ # What fields/rows on the class is supposed to be used by the Gem to generate the xml
160
+ # This method uses #serialize_variables.
161
+ def get_import_rows
162
+ serialize_variables.map do |p|
163
+ map_to_row p
164
+ end
165
+ end
166
+
167
+ # @!visibility private
168
+ def self.get_import_rows(type)
169
+ case type
170
+ when :person then
171
+ Person.new
172
+ when :source_ref then
173
+ ReferenceToSource.new
174
+ when :history then
175
+ History.new
176
+ when :address then
177
+ Address.new
178
+ when :organization then
179
+ Organization.new
180
+ when :coworker_reference then
181
+ CoworkerReference.new
182
+ when :organization_reference then
183
+ OrganizationReference.new
184
+ when :custom_field then
185
+ CustomField.new
186
+ when :custom_value then
187
+ CustomValue.new
188
+ when :custom_field_reference then
189
+ CustomFieldReference.new
190
+ when :settings then
191
+ Settings.new
192
+ when :class_settings then
193
+ ClassSettings.new
194
+ else
195
+ raise "Unknown type: #{type}"
196
+ end.get_import_rows
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,96 @@
1
+ module MoveToGo
2
+ class ShardHelper
3
+
4
+ attr_accessor :shards, :current_shard_count, :current_shard
5
+
6
+ def initialize(shard_size = nil)
7
+ @shard_size = shard_size || 25000
8
+ setup()
9
+ end
10
+
11
+ def shard_model(model)
12
+ @current_shard.settings = model.settings
13
+
14
+ model.coworkers.each{ |key, coworker|
15
+ if coworker.integration_id != "migrator"
16
+ add_coworker(coworker)
17
+ end
18
+ }
19
+ model.organizations.each{|key, org| add_organization(org)}
20
+ model.deals.each{|key, deal| add_deal(deal)}
21
+ model.histories.each{|key, history| add_history(history)}
22
+ add_documents(model.documents)
23
+
24
+ return_value = @shards
25
+ setup()
26
+ return return_value
27
+ end
28
+
29
+ private
30
+ def setup()
31
+ @current_shard = MoveToGo::RootModel.new
32
+ @shards = [@current_shard]
33
+ @current_shard_count = 0
34
+ end
35
+
36
+ private
37
+ def add_history(history)
38
+ check_or_create_new_chard()
39
+ @current_shard.add_history(history)
40
+ @current_shard_count += 1
41
+ end
42
+
43
+ private
44
+ def add_deal(deal)
45
+ check_or_create_new_chard()
46
+ @current_shard.add_deal(deal)
47
+ @current_shard_count += 1
48
+ end
49
+
50
+ private
51
+ def add_coworker(coworker)
52
+ check_or_create_new_chard()
53
+ @current_shard.add_coworker(coworker)
54
+ @current_shard_count += 1
55
+ end
56
+
57
+ private
58
+ def add_organization(org)
59
+ check_or_create_new_chard()
60
+ if org.employees != nil
61
+ @current_shard_count += org.employees.length
62
+ end
63
+ @current_shard.add_organization(org)
64
+ @current_shard_count += 1
65
+ end
66
+
67
+ private
68
+ def add_documents(doc)
69
+ doc.files.each{|file| add_file(file)}
70
+ doc.links.each{|link| add_link(link)}
71
+ end
72
+
73
+ private
74
+ def add_file(file)
75
+ check_or_create_new_chard()
76
+ @current_shard.add_file(file)
77
+ @current_shard_count += 1
78
+ end
79
+
80
+ private
81
+ def add_link(link)
82
+ check_or_create_new_chard()
83
+ @current_shard.add_link(link)
84
+ @current_shard_count += 1
85
+ end
86
+
87
+ private
88
+ def check_or_create_new_chard()
89
+ if @current_shard_count > @shard_size
90
+ @current_shard = MoveToGo::RootModel.new
91
+ @shards.push(@current_shard)
92
+ @current_shard_count = 0
93
+ end
94
+ end
95
+ end
96
+ end