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,47 @@
1
+ module MoveToGo
2
+ class DealStatusReference
3
+ include SerializeHelper
4
+
5
+ attr_accessor :label, :integration_id
6
+
7
+ def initialize(opt = nil)
8
+ if opt != nil
9
+ serialize_variables.each do |myattr|
10
+ val = opt[myattr[:id]]
11
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
12
+ end
13
+ end
14
+ end
15
+
16
+ def serialize_variables
17
+ [:integration_id, :label].map {|p| {:id => p, :type => :string} }
18
+ end
19
+
20
+ def serialize_name
21
+ "StatusReference"
22
+ end
23
+
24
+ # Converts the specifed status to a status reference.
25
+ def self.from_deal_status(deal_status)
26
+ if deal_status.nil?
27
+ return nil
28
+ elsif deal_status.is_a?(DealStatusSetting)
29
+ return deal_status.to_reference
30
+ elsif deal_status.is_a?(String)
31
+ return DealStatusReference.new({:label => deal_status, :integration_id => deal_status})
32
+ end
33
+
34
+ raise InvalidDealStatusError
35
+ end
36
+
37
+ def validate
38
+ error = ""
39
+
40
+ if (@label.nil? || @label.empty?) && (@integration_id.nil? || @integration_id.empty?)
41
+ error = "label and integration_id can't all be nil or empty"
42
+ end
43
+
44
+ return error
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ module MoveToGo
3
+ class DealStatusSetting
4
+ include SerializeHelper
5
+
6
+ attr_accessor :id, :integration_id, :label, :assessment
7
+
8
+ def initialize(opt = nil)
9
+ if opt != nil
10
+ serialize_variables.each do |myattr|
11
+ val = opt[myattr[:id]]
12
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
13
+ end
14
+ end
15
+ end
16
+
17
+ def serialize_variables
18
+ [ :id, :integration_id, :label, :assessment ].map{ |p| { :id => p, :type => :string } }
19
+ end
20
+
21
+ def serialize_name
22
+ "DealStatus"
23
+ end
24
+
25
+ def to_reference()
26
+ reference = DealStatusReference.new
27
+ reference.label = @label
28
+ reference.integration_id = @integration_id
29
+
30
+ return reference
31
+ end
32
+
33
+ def same_as?(other)
34
+ if @integration_id != nil && @integration_id == other.integration_id
35
+ return true
36
+ end
37
+
38
+ if @id != nil && @id == other.id
39
+ return true
40
+ end
41
+
42
+ if @label != nil && @label == other.label
43
+ return true
44
+ end
45
+
46
+ return false
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ module MoveToGo
3
+ # This class is the container for all documents, ie links and
4
+ # files.
5
+ class Documents
6
+ include SerializeHelper
7
+
8
+ attr_reader :links, :files
9
+
10
+ def serialize_variables
11
+ [
12
+ {:id => :links, @type => :links},
13
+ {:id => :files, @type => :files}
14
+ ]
15
+ end
16
+
17
+ def serialize_name
18
+ "Documents"
19
+ end
20
+
21
+ def initialize
22
+ @links = []
23
+ @files = []
24
+ end
25
+
26
+ def add_link(link)
27
+ @links = [] if @links == nil
28
+
29
+ if link.nil?
30
+ return nil
31
+ end
32
+
33
+ link = Link.new(link) if !link.is_a?(Link)
34
+
35
+ if (!link.integration_id.nil? && link.integration_id.length > 0) &&
36
+ find_link_by_integration_id(link.integration_id) != nil
37
+ raise AlreadyAddedError, "Already added a link with integration_id '#{link.integration_id}'."
38
+ end
39
+
40
+ @links.push link
41
+
42
+ return link
43
+ end
44
+
45
+ def find_link_by_integration_id(integration_id)
46
+ return @links.find do |link|
47
+ link.integration_id == integration_id
48
+ end
49
+ end
50
+
51
+ def add_file(file)
52
+ @files = [] if @files == nil
53
+
54
+ if file.nil?
55
+ return nil
56
+ end
57
+
58
+ file = File.new(file) if !file.is_a?(File)
59
+
60
+ if (!file.integration_id.nil? && file.integration_id.length > 0) &&
61
+ find_file_by_integration_id(file.integration_id) != nil
62
+ raise AlreadyAddedError, "Already added a file with integration_id '#{file.integration_id}'."
63
+ end
64
+
65
+ @files.push file
66
+
67
+ return file
68
+ end
69
+
70
+ def find_file_by_integration_id(integration_id)
71
+ return @files.find do |file|
72
+ file.integration_id == integration_id
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,193 @@
1
+ require 'pathname'
2
+ require_relative '../serialize_helper'
3
+
4
+ # Note that we name this class File and ruby alread have a File class.
5
+ # To refrence to this
6
+
7
+ module MoveToGo
8
+ class File
9
+ DEFAULT_MAX_FILE_SIZE = 100000000 # 100 Mb
10
+
11
+ include SerializeHelper
12
+ attr_accessor :id, :integration_id, :description
13
+
14
+ attr_reader :organization, :created_by, :deal
15
+
16
+ attr_reader :path
17
+
18
+ attr_reader :name
19
+
20
+ # location_in_zip_file is used internally when the file is
21
+ # stored in the zip file that is sent to LIME Go. You should
22
+ # not modify this property
23
+ attr_accessor :location_in_zip_file
24
+
25
+ def initialize(opt = nil)
26
+ if !opt.nil?
27
+ serialize_variables.each do |myattr|
28
+ val = opt[myattr[:id]]
29
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
30
+ end
31
+ end
32
+ end
33
+
34
+ def serialize_name
35
+ "File"
36
+ end
37
+
38
+ def serialize_variables
39
+ [ :id, :integration_id, :path, :name, :description, :location_in_zip_file ].map {
40
+ |p| {
41
+ :id => p,
42
+ :type => :string
43
+ }
44
+ } +
45
+ [
46
+ { :id => :created_by_reference, :type => :coworker_reference, :element_name => :created_by },
47
+ { :id => :organization_reference, :type => :organization_reference, :element_name => :organization },
48
+ { :id => :deal_reference, :type => :deal_reference, :element_name => :deal }
49
+ ]
50
+ end
51
+
52
+ def path=(path)
53
+ @path = path
54
+
55
+ # when path is set, we should set the name to the path's
56
+ # filename if name is NOT set already
57
+
58
+ # Hm. this might introduce a bug if we set path twice and
59
+ # never explicity set the name (it will get the name of
60
+ # the first file)
61
+
62
+ if (@name.nil? || @name.empty?) && (!@path.nil? && !@path.empty?)
63
+ @name = Pathname.new(path).basename.to_s
64
+ end
65
+ @location_in_zip_file = "files/#{SecureRandom.uuid}#{::File.extname(@path).to_s}"
66
+
67
+ end
68
+
69
+ def name=(name)
70
+ @name = name
71
+
72
+ # a file must have a name, hence this.
73
+
74
+ if @name.nil? || @name.empty?
75
+ if !@path.nil? && !@path.empty?
76
+ @name = Pathname.new(@path).basename.to_s
77
+ end
78
+ end
79
+ end
80
+
81
+ def has_relative_path?()
82
+ return !@path.match(/[a-zA-Z]{1}\:[\\\/]/)&&Pathname.new(@path).relative?
83
+ end
84
+
85
+ def organization=(org)
86
+ @organization_reference = OrganizationReference.from_organization(org)
87
+
88
+ if org.is_a?(Organization)
89
+ @organization = org
90
+ end
91
+ end
92
+
93
+ def deal=(deal)
94
+ @deal_reference = DealReference.from_deal(deal)
95
+
96
+ if deal.is_a?(Deal)
97
+ @deal = deal
98
+ end
99
+ end
100
+
101
+ def created_by=(coworker)
102
+ @created_by_reference = CoworkerReference.from_coworker(coworker)
103
+
104
+ if coworker.is_a?(Coworker)
105
+ @created_by = coworker
106
+ end
107
+ end
108
+
109
+ # This is the path to where the file should be accessed
110
+ # from within the project.
111
+ def path_for_project
112
+ if @path.nil? || @path.empty?
113
+ return ""
114
+ end
115
+
116
+ # Get the folder where files should be accessed from
117
+ # during the import. If not defined in converter.rb use
118
+ # the current directory
119
+ if defined?(FILES_FOLDER) && !FILES_FOLDER.empty?()
120
+ root_folder = FILES_FOLDER
121
+ else
122
+ root_folder = Dir.pwd
123
+ end
124
+
125
+ if has_relative_path?()
126
+ # since this file is stored with a relative file name
127
+ # we should get it from the root folder
128
+ path_for_project = ::File.expand_path(@path, root_folder)
129
+ else
130
+ # the file is stored with an absolute path, if the
131
+ # file cant be access using that path we must change
132
+ # it to a path that is accessible from this computer.
133
+ # The FILES_FOLDER_AT_CUSTOMER constant states what
134
+ # part of the path that should be replaced with the
135
+ # root folder.
136
+
137
+ # We assume that the original system used ONE location
138
+ # for all its files. If not, we should change
139
+ # FILES_FOLDER_AT_CUSTOMER to a list of folders.
140
+ if defined?(FILES_FOLDER_AT_CUSTOMER) && !FILES_FOLDER_AT_CUSTOMER.empty?()
141
+ files_folder_at_customer = FILES_FOLDER_AT_CUSTOMER
142
+ else
143
+ files_folder_at_customer = ""
144
+ end
145
+
146
+ if files_folder_at_customer.empty?
147
+ path_for_project = @path
148
+ else
149
+ path_for_project = ::File.expand_path(@path.downcase.sub(files_folder_at_customer.downcase, root_folder))
150
+ end
151
+ end
152
+
153
+ return path_for_project
154
+ end
155
+
156
+ def add_to_zip_file(zip_file)
157
+ zip_file.add(@location_in_zip_file, path_for_project)
158
+ end
159
+
160
+ def validate(ignore_invalid_files = false, max_file_size = DEFAULT_MAX_FILE_SIZE)
161
+ error = String.new
162
+ warning = String.new
163
+
164
+ if @name.nil? || @name.empty?
165
+ error = "#{error}A file must have a name.\n"
166
+ end
167
+
168
+ if @path.nil? || @path.empty?
169
+ error = "Path is required for file.\n"
170
+ elsif !ignore_invalid_files
171
+ if !::File.exists?(path_for_project())
172
+ error = "#{error}Can't find file with name '#{@name}' and original path '#{@path}' at '#{path_for_project()}'."
173
+ elsif ::File.exists?(path_for_project) && ::File.size(path_for_project()) > max_file_size
174
+ error = "#{error}File '#{@name}' is bigger than #{max_file_size} bytes."
175
+ end
176
+ end
177
+
178
+ if @created_by_reference.nil?
179
+ error = "#{error}Created_by is required for file (#{@name}).\n"
180
+ end
181
+
182
+ if @organization_reference.nil? && @deal_reference.nil?
183
+ error = "#{error}The file (#{@name}) must have either an organization or a deal.\n"
184
+ end
185
+
186
+ if !@organization_reference.nil? && !@deal_reference.nil?
187
+ error = "#{error}The file (#{@name}) can't be attached to both an organization and a deal."
188
+ end
189
+
190
+ return error
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,148 @@
1
+ module MoveToGo
2
+ class History < CanBecomeImmutable
3
+ include SerializeHelper
4
+ immutable_accessor :id
5
+ immutable_accessor :integration_id
6
+ immutable_accessor :date
7
+
8
+ attr_reader :text
9
+ attr_reader :organization, :created_by, :person, :deal
10
+
11
+ # The history classification. It should be a value from
12
+ # {#HistoryClassification}. The default value is Comment.
13
+ attr_reader :classification
14
+
15
+ def initialize(opt = nil)
16
+ if !opt.nil?
17
+ serialize_variables.each do |myattr|
18
+ val = opt[myattr[:id]]
19
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
20
+ end
21
+ end
22
+
23
+ @classification = HistoryClassification::Comment if @classification.nil?
24
+ end
25
+
26
+ def serialize_variables
27
+ [ :id, :text, :integration_id, :classification ].map {
28
+ |p| {
29
+ :id => p,
30
+ :type => :string
31
+ }
32
+ } +
33
+ [
34
+ { :id => :date, :type => :date },
35
+ { :id => :created_by_reference, :type => :coworker_reference, :element_name => :created_by },
36
+ { :id => :organization_reference, :type => :organization_reference, :element_name => :organization },
37
+ { :id => :deal_reference, :type => :deal_reference, :element_name => :deal },
38
+ { :id => :person_reference, :type => :person_reference, :element_name => :person }
39
+ ]
40
+ end
41
+
42
+ def get_import_rows
43
+ (serialize_variables + [
44
+ { :id => :organization, :type => :organization_reference},
45
+ { :id => :person, :type => :person_reference}
46
+ ]).map do |p|
47
+ map_to_row p
48
+ end
49
+ end
50
+
51
+ def serialize_name
52
+ "History"
53
+ end
54
+
55
+ def organization=(org)
56
+ raise_if_immutable
57
+ @organization_reference = OrganizationReference.from_organization(org)
58
+
59
+ if org.is_a?(Organization)
60
+ @organization = org
61
+ end
62
+ end
63
+
64
+ def created_by=(coworker)
65
+ raise_if_immutable
66
+ @created_by_reference = CoworkerReference.from_coworker(coworker)
67
+
68
+ if coworker.is_a?(Coworker)
69
+ @created_by = coworker
70
+ end
71
+ end
72
+
73
+ def person=(person)
74
+ raise_if_immutable
75
+ @person_reference = PersonReference.from_person(person)
76
+
77
+ if person.is_a?(Person)
78
+ @person = person
79
+ end
80
+ end
81
+
82
+ def deal=(deal)
83
+ raise_if_immutable
84
+ @deal_reference = DealReference.from_deal(deal)
85
+
86
+ if deal.is_a?(Deal)
87
+ @deal = deal
88
+ end
89
+ end
90
+
91
+ def classification=(classification)
92
+ raise_if_immutable
93
+ if classification == HistoryClassification::Comment || classification == HistoryClassification::SalesCall ||
94
+ classification == HistoryClassification::TalkedTo || classification == HistoryClassification::TriedToReach ||
95
+ classification == HistoryClassification::ClientVisit
96
+ @classification = classification
97
+ else
98
+ raise InvalidHistoryClassificationError, classification
99
+ end
100
+ end
101
+
102
+ def text=(text)
103
+ raise_if_immutable
104
+ @text = text
105
+
106
+ if @text.nil?
107
+ return
108
+ end
109
+
110
+ if @text.length == 0
111
+ return
112
+ end
113
+
114
+ @text.strip!
115
+
116
+ # remove form feeds
117
+ @text.gsub!("\f", "")
118
+
119
+ # remove vertical spaces
120
+ @text.gsub!("\v", "")
121
+
122
+ # remove backspace
123
+ @text.gsub!("\b", "")
124
+ end
125
+
126
+ def validate
127
+ error = String.new
128
+
129
+ if (@classification.nil? || @classification.empty?)
130
+ error = "Classification is required for history\n"
131
+ end
132
+
133
+ if (@text.nil? || @text.empty?) && classification != HistoryClassification::TriedToReach
134
+ error = "Text is required for history\n"
135
+ end
136
+
137
+ if @created_by.nil?
138
+ error = "#{error}Created_by is required for history\n"
139
+ end
140
+
141
+ if @organization.nil? && @deal.nil? && @person.nil?
142
+ error = "#{error}Organization, deal or person is required for history\n"
143
+ end
144
+
145
+ return error
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,26 @@
1
+ module MoveToGo
2
+ # Defines a history type. This defines what kind of
3
+ # action that happened before the history was written.
4
+ module HistoryClassification
5
+ # We talked to the client about a sale. This might be a phone call
6
+ # or a talk in person.
7
+ SalesCall = 'SalesCall'
8
+
9
+ # This is a general comment about the organization or deal.
10
+ Comment = 'Comment'
11
+
12
+ # This is a general comment regarding a talk we had with
13
+ # someone at the client.
14
+ TalkedTo = 'TalkedTo'
15
+
16
+ # We tried to reach someone but failed.
17
+ TriedToReach = 'TriedToReach'
18
+
19
+ # We had a meeting at the client's site.
20
+ ClientVisit = 'ClientVisit'
21
+ end
22
+ end
23
+
24
+
25
+
26
+
@@ -0,0 +1,82 @@
1
+ module MoveToGo
2
+ class Link
3
+ include SerializeHelper
4
+ attr_accessor :id, :integration_id, :url, :name, :description
5
+
6
+ attr_reader :organization, :created_by, :deal
7
+
8
+ def initialize(opt = nil)
9
+ if !opt.nil?
10
+ serialize_variables.each do |myattr|
11
+ val = opt[myattr[:id]]
12
+ instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
13
+ end
14
+ end
15
+ end
16
+
17
+ def serialize_name
18
+ "Link"
19
+ end
20
+
21
+ def serialize_variables
22
+ [ :id, :integration_id, :url, :name, :description ].map {
23
+ |p| {
24
+ :id => p,
25
+ :type => :string
26
+ }
27
+ } +
28
+ [
29
+ { :id => :created_by_reference, :type => :coworker_reference, :element_name => :created_by },
30
+ { :id => :organization_reference, :type => :organization_reference, :element_name => :organization },
31
+ { :id => :deal_reference, :type => :deal_reference, :element_name => :deal }
32
+ ]
33
+ end
34
+
35
+ def organization=(org)
36
+ @organization_reference = OrganizationReference.from_organization(org)
37
+
38
+ if org.is_a?(Organization)
39
+ @organization = org
40
+ end
41
+ end
42
+
43
+ def deal=(deal)
44
+ @deal_reference = DealReference.from_deal(deal)
45
+
46
+ if deal.is_a?(Deal)
47
+ @deal = deal
48
+ end
49
+ end
50
+
51
+ def created_by=(coworker)
52
+ @created_by_reference = CoworkerReference.from_coworker(coworker)
53
+
54
+ if coworker.is_a?(Coworker)
55
+ @created_by = coworker
56
+ end
57
+ end
58
+
59
+ def validate
60
+ error = String.new
61
+
62
+ if @url.nil? || @url.empty?
63
+ error = "Url is required for link\n"
64
+ end
65
+
66
+ if @created_by_reference.nil?
67
+ error = "#{error}Created_by is required for link\n"
68
+ end
69
+
70
+ if @organization_reference.nil? && @deal_reference.nil?
71
+ error = "#{error}A link must have either an organization or a deal\n"
72
+ end
73
+
74
+ if !@organization_reference.nil? && !@deal_reference.nil?
75
+ error = "#{error}A link can't be attached to both an organization and a deal"
76
+ end
77
+
78
+ return error
79
+ end
80
+ end
81
+ end
82
+