fruit_to_lime 2.5.5 → 2.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/fruit_to_lime.rb +17 -17
- data/lib/fruit_to_lime/csv_helper.rb +47 -47
- data/lib/fruit_to_lime/email_helper.rb +10 -10
- data/lib/fruit_to_lime/errors.rb +16 -16
- data/lib/fruit_to_lime/excel_helper.rb +10 -10
- data/lib/fruit_to_lime/global_phone.json +6571 -6571
- data/lib/fruit_to_lime/model/address.rb +60 -60
- data/lib/fruit_to_lime/model/class_settings.rb +50 -50
- data/lib/fruit_to_lime/model/coworker.rb +76 -76
- data/lib/fruit_to_lime/model/coworker_reference.rb +33 -33
- data/lib/fruit_to_lime/model/customfield.rb +87 -87
- data/lib/fruit_to_lime/model/deal.rb +141 -141
- data/lib/fruit_to_lime/model/deal_status.rb +12 -12
- data/lib/fruit_to_lime/model/note.rb +80 -79
- data/lib/fruit_to_lime/model/organization.rb +203 -203
- data/lib/fruit_to_lime/model/person.rb +151 -151
- data/lib/fruit_to_lime/model/referencetosource.rb +45 -45
- data/lib/fruit_to_lime/model/relation.rb +23 -23
- data/lib/fruit_to_lime/model/rootmodel.rb +342 -338
- data/lib/fruit_to_lime/model/settings.rb +60 -60
- data/lib/fruit_to_lime/model/tag.rb +35 -35
- data/lib/fruit_to_lime/model_helpers.rb +54 -54
- data/lib/fruit_to_lime/phone_helper.rb +74 -74
- data/lib/fruit_to_lime/roo_helper.rb +72 -72
- data/lib/fruit_to_lime/serialize_helper.rb +186 -186
- data/lib/fruit_to_lime/templating.rb +52 -52
- data/spec/address_spec.rb +48 -48
- data/spec/class_settings_spec.rb +37 -37
- data/spec/coworker_spec.rb +94 -94
- data/spec/custom_field_spec.rb +22 -22
- data/spec/deal_spec.rb +101 -101
- data/spec/helpers/csv_helper_spec.rb +29 -29
- data/spec/helpers/email_helper_spec.rb +32 -32
- data/spec/helpers/phone_helper_spec.rb +97 -97
- data/spec/helpers/serialize_helper_spec.rb +249 -249
- data/spec/helpers/xsd_validate_spec.rb +58 -58
- data/spec/note_spec.rb +98 -98
- data/spec/organization_spec.rb +103 -103
- data/spec/person_spec.rb +134 -134
- data/spec/rootmodel_spec.rb +306 -277
- data/spec/templating_spec.rb +11 -11
- data/templates/csv/lib/tomodel.rb +230 -230
- data/templates/csv/spec/exporter_spec.rb +17 -17
- data/templates/csv/spec/sample_data/coworkers.csv +2 -2
- data/templates/csv/spec/sample_data/deals.csv +2 -2
- data/templates/csv/spec/sample_data/organizations.csv +2 -2
- data/templates/csv/spec/sample_data/persons.csv +2 -2
- data/templates/easy/Gemfile +5 -5
- data/templates/easy/Rakefile.rb +7 -7
- data/templates/easy/convert.rb +2 -2
- data/templates/easy/spec/exporter_spec.rb +10 -10
- data/templates/easy/spec/spec_helper.rb +24 -24
- data/templates/excel/lib/tomodel.rb +207 -207
- data/templates/sqlserver/lib/tomodel.rb +79 -79
- metadata +3 -3
@@ -1,46 +1,46 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
class ReferenceToSource
|
3
|
-
include SerializeHelper
|
4
|
-
attr_accessor :name, :id, :format
|
5
|
-
|
6
|
-
def serialize_variables
|
7
|
-
[:name, :format, :id].map { |prop| { :id => prop, :type => :string } }
|
8
|
-
end
|
9
|
-
|
10
|
-
def serialize_name
|
11
|
-
"ReferenceToSource"
|
12
|
-
end
|
13
|
-
|
14
|
-
def get_import_rows
|
15
|
-
(serialize_variables + [{ :id => :value, :type => :string }]).map do |p|
|
16
|
-
map_to_row p
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(opt = nil)
|
21
|
-
if opt != nil
|
22
|
-
serialize_variables.each do |myattr|
|
23
|
-
val = opt[myattr[:id]]
|
24
|
-
instance_variable_set("@" + myattr[:id].to_s,val) if val != nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_s
|
30
|
-
return "#{@name}_#{@format}_#{@id}"
|
31
|
-
end
|
32
|
-
|
33
|
-
def ==(other)
|
34
|
-
if other==nil
|
35
|
-
return false
|
36
|
-
end
|
37
|
-
return @name == other.name && @id == other.id && @format== other.format
|
38
|
-
end
|
39
|
-
# Sets the id of this instance to the parameter supplied. Will also set {#name} and {#format} so that this reference is identified as a PAR identifier by Go.
|
40
|
-
def par_se(id)
|
41
|
-
@name = 'pase'
|
42
|
-
@format = 'External'
|
43
|
-
@id = id
|
44
|
-
end
|
45
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
class ReferenceToSource
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :name, :id, :format
|
5
|
+
|
6
|
+
def serialize_variables
|
7
|
+
[:name, :format, :id].map { |prop| { :id => prop, :type => :string } }
|
8
|
+
end
|
9
|
+
|
10
|
+
def serialize_name
|
11
|
+
"ReferenceToSource"
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_import_rows
|
15
|
+
(serialize_variables + [{ :id => :value, :type => :string }]).map do |p|
|
16
|
+
map_to_row p
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(opt = nil)
|
21
|
+
if opt != nil
|
22
|
+
serialize_variables.each do |myattr|
|
23
|
+
val = opt[myattr[:id]]
|
24
|
+
instance_variable_set("@" + myattr[:id].to_s,val) if val != nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
return "#{@name}_#{@format}_#{@id}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def ==(other)
|
34
|
+
if other==nil
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
return @name == other.name && @id == other.id && @format== other.format
|
38
|
+
end
|
39
|
+
# Sets the id of this instance to the parameter supplied. Will also set {#name} and {#format} so that this reference is identified as a PAR identifier by Go.
|
40
|
+
def par_se(id)
|
41
|
+
@name = 'pase'
|
42
|
+
@format = 'External'
|
43
|
+
@id = id
|
44
|
+
end
|
45
|
+
end
|
46
46
|
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
module FruitToLime
|
2
|
-
module Relation
|
3
|
-
# This is the default, we have not been in contact with this
|
4
|
-
# organization in any way.
|
5
|
-
NoRelation = 0
|
6
|
-
|
7
|
-
# Something is happening with this organization, we might have
|
8
|
-
# booked a meeting with them or created a deal, etc.
|
9
|
-
WorkingOnIt = 1
|
10
|
-
|
11
|
-
# We have made a deal with this organization.
|
12
|
-
IsACustomer = 2
|
13
|
-
|
14
|
-
# We have made a deal with this organization but it was some
|
15
|
-
# time ago and we don't consider them a customer any more.
|
16
|
-
WasACustomer = 3
|
17
|
-
|
18
|
-
# We had something going with this organization but we
|
19
|
-
# couldn't close the deal and we don't think they will be a
|
20
|
-
# customer to us in the foreseeable future.
|
21
|
-
BeenInTouch = 4
|
22
|
-
end
|
23
|
-
end
|
1
|
+
module FruitToLime
|
2
|
+
module Relation
|
3
|
+
# This is the default, we have not been in contact with this
|
4
|
+
# organization in any way.
|
5
|
+
NoRelation = 0
|
6
|
+
|
7
|
+
# Something is happening with this organization, we might have
|
8
|
+
# booked a meeting with them or created a deal, etc.
|
9
|
+
WorkingOnIt = 1
|
10
|
+
|
11
|
+
# We have made a deal with this organization.
|
12
|
+
IsACustomer = 2
|
13
|
+
|
14
|
+
# We have made a deal with this organization but it was some
|
15
|
+
# time ago and we don't consider them a customer any more.
|
16
|
+
WasACustomer = 3
|
17
|
+
|
18
|
+
# We had something going with this organization but we
|
19
|
+
# couldn't close the deal and we don't think they will be a
|
20
|
+
# customer to us in the foreseeable future.
|
21
|
+
BeenInTouch = 4
|
22
|
+
end
|
23
|
+
end
|
@@ -1,338 +1,342 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
module FruitToLime
|
3
|
-
# The root model for Go import. This class is the container for everything else.
|
4
|
-
class RootModel
|
5
|
-
# the import_coworker is a special coworker that is set as
|
6
|
-
# responsible for objects that requires a coworker, eg a note.
|
7
|
-
attr_accessor :import_coworker
|
8
|
-
|
9
|
-
attr_accessor :settings, :organizations, :coworkers, :deals, :notes
|
10
|
-
def serialize_variables
|
11
|
-
[
|
12
|
-
{:id => :settings, :type => :settings},
|
13
|
-
{:id => :coworkers, :type => :coworkers},
|
14
|
-
{:id => :organizations, :type => :organizations},
|
15
|
-
{:id => :deals, :type => :deals},
|
16
|
-
{:id => :notes, :type => :notes},
|
17
|
-
]
|
18
|
-
end
|
19
|
-
|
20
|
-
def serialize_name
|
21
|
-
"GoImport"
|
22
|
-
end
|
23
|
-
|
24
|
-
include SerializeHelper
|
25
|
-
|
26
|
-
def initialize()
|
27
|
-
@settings = Settings.new
|
28
|
-
@organizations = []
|
29
|
-
@coworkers = []
|
30
|
-
@import_coworker = Coworker.new
|
31
|
-
@import_coworker.integration_id = "import"
|
32
|
-
@import_coworker.first_name = "Import"
|
33
|
-
@coworkers.push @import_coworker
|
34
|
-
@deals = []
|
35
|
-
@notes = []
|
36
|
-
end
|
37
|
-
|
38
|
-
# Adds the specifed coworker object to the model.
|
39
|
-
# @example Add a coworker from a hash
|
40
|
-
# rootmodel.add_coworker({
|
41
|
-
# :integration_id=>"123",
|
42
|
-
# :first_name=>"Kalle",
|
43
|
-
# :last_name=>"Anka",
|
44
|
-
# :email=>"kalle.anka@vonanka.com"
|
45
|
-
# })
|
46
|
-
#
|
47
|
-
# @example Add a coworker from a new coworker
|
48
|
-
# coworker = FruitToLime::Coworker.new
|
49
|
-
# coworker.integration_id = "123"
|
50
|
-
# coworker.first_name="Kalle"
|
51
|
-
# coworker.last_name="Anka"
|
52
|
-
# coworker.email = "kalle.anka@vonanka.com"
|
53
|
-
# rootmodel.add_coworker(coworker)
|
54
|
-
#
|
55
|
-
# @example If you want to keep adding coworkers and dont care about duplicates not being added
|
56
|
-
# begin
|
57
|
-
# rootmodel.add_coworker(coworker)
|
58
|
-
# rescue FruitToLime::AlreadyAddedError
|
59
|
-
# puts "Warning: already added coworker"
|
60
|
-
# end
|
61
|
-
# @see Coworker
|
62
|
-
def add_coworker(coworker)
|
63
|
-
@coworkers = [] if @coworkers == nil
|
64
|
-
|
65
|
-
if coworker == nil
|
66
|
-
raise "Missing coworker to add!"
|
67
|
-
end
|
68
|
-
|
69
|
-
coworker = Coworker.new(coworker) if !coworker.is_a?(Coworker)
|
70
|
-
|
71
|
-
if find_coworker_by_integration_id(coworker.integration_id) != nil
|
72
|
-
raise AlreadyAddedError, "Already added a coworker with integration_id #{coworker.integration_id}"
|
73
|
-
end
|
74
|
-
|
75
|
-
@coworkers.push(coworker)
|
76
|
-
|
77
|
-
return coworker
|
78
|
-
end
|
79
|
-
|
80
|
-
# Adds the specifed organization object to the model.
|
81
|
-
# @example Add an organization from a hash
|
82
|
-
# rootmodel.add_organization({
|
83
|
-
# :integration_id => "123",
|
84
|
-
# :name => "Beagle Boys",
|
85
|
-
# })
|
86
|
-
#
|
87
|
-
# @example Add an organization from a new organization
|
88
|
-
# organization = FruitToLime::Organization.new
|
89
|
-
# organization.integration_id = "123"
|
90
|
-
# organization.name = "Beagle Boys"
|
91
|
-
# rootmodel.add_organization(organization)
|
92
|
-
#
|
93
|
-
# @example If you want to keep adding organizations and dont
|
94
|
-
# care about duplicates not being added. Your model might not
|
95
|
-
# be saved due to duplicate integration_ids.
|
96
|
-
# begin
|
97
|
-
# rootmodel.add_organization(organization)
|
98
|
-
# rescue FruitToLime::AlreadyAddedError
|
99
|
-
# puts "Warning: already added organization"
|
100
|
-
# end
|
101
|
-
# @see Coworker
|
102
|
-
def add_organization(organization)
|
103
|
-
@organizations = [] if @organizations.nil?
|
104
|
-
|
105
|
-
if organization.nil?
|
106
|
-
raise "Missing organization to add"
|
107
|
-
end
|
108
|
-
|
109
|
-
organization = Organization.new(organization) if !organization.is_a?(Organization)
|
110
|
-
|
111
|
-
if find_organization_by_integration_id(organization.integration_id) != nil
|
112
|
-
raise AlreadyAddedError, "Already added an organization with integration_id #(organization.integration_id)"
|
113
|
-
end
|
114
|
-
|
115
|
-
@organizations.push(organization)
|
116
|
-
|
117
|
-
return organization
|
118
|
-
end
|
119
|
-
|
120
|
-
# Adds the specifed deal object to the model.
|
121
|
-
# @example Add an deal from a hash
|
122
|
-
# rootmodel.add_deal({
|
123
|
-
# :integration_id => "123",
|
124
|
-
# :name => "Big deal",
|
125
|
-
# })
|
126
|
-
#
|
127
|
-
# @example Add a deal from a new deal
|
128
|
-
# deal = FruitToLime::Deal.new
|
129
|
-
# deal.integration_id = "123"
|
130
|
-
# deal.name = "Big deal"
|
131
|
-
# rootmodel.add_deal(deal)
|
132
|
-
#
|
133
|
-
# @example If you want to keep adding deals and dont
|
134
|
-
# care about duplicates not being added. Your model might not
|
135
|
-
# be saved due to duplicate integration_ids.
|
136
|
-
# begin
|
137
|
-
# rootmodel.add_deal(deal)
|
138
|
-
# rescue FruitToLime::AlreadyAddedError
|
139
|
-
# puts "Warning: already added deal"
|
140
|
-
# end
|
141
|
-
# @see Coworker
|
142
|
-
def add_deal(deal)
|
143
|
-
@deals = [] if @deals.nil?
|
144
|
-
|
145
|
-
if deal.nil?
|
146
|
-
raise "Missing deal to add"
|
147
|
-
end
|
148
|
-
|
149
|
-
deal = Deal.new(deal) if !deal.is_a?(Deal)
|
150
|
-
|
151
|
-
if find_deal_by_integration_id(deal.integration_id) != nil
|
152
|
-
raise AlreadyAddedError, "Already added a deal with integration_id #{deal.integration_id}"
|
153
|
-
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
return
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
dups
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
dups
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
error
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
return objects
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
module FruitToLime
|
3
|
+
# The root model for Go import. This class is the container for everything else.
|
4
|
+
class RootModel
|
5
|
+
# the import_coworker is a special coworker that is set as
|
6
|
+
# responsible for objects that requires a coworker, eg a note.
|
7
|
+
attr_accessor :import_coworker
|
8
|
+
|
9
|
+
attr_accessor :settings, :organizations, :coworkers, :deals, :notes
|
10
|
+
def serialize_variables
|
11
|
+
[
|
12
|
+
{:id => :settings, :type => :settings},
|
13
|
+
{:id => :coworkers, :type => :coworkers},
|
14
|
+
{:id => :organizations, :type => :organizations},
|
15
|
+
{:id => :deals, :type => :deals},
|
16
|
+
{:id => :notes, :type => :notes},
|
17
|
+
]
|
18
|
+
end
|
19
|
+
|
20
|
+
def serialize_name
|
21
|
+
"GoImport"
|
22
|
+
end
|
23
|
+
|
24
|
+
include SerializeHelper
|
25
|
+
|
26
|
+
def initialize()
|
27
|
+
@settings = Settings.new
|
28
|
+
@organizations = []
|
29
|
+
@coworkers = []
|
30
|
+
@import_coworker = Coworker.new
|
31
|
+
@import_coworker.integration_id = "import"
|
32
|
+
@import_coworker.first_name = "Import"
|
33
|
+
@coworkers.push @import_coworker
|
34
|
+
@deals = []
|
35
|
+
@notes = []
|
36
|
+
end
|
37
|
+
|
38
|
+
# Adds the specifed coworker object to the model.
|
39
|
+
# @example Add a coworker from a hash
|
40
|
+
# rootmodel.add_coworker({
|
41
|
+
# :integration_id=>"123",
|
42
|
+
# :first_name=>"Kalle",
|
43
|
+
# :last_name=>"Anka",
|
44
|
+
# :email=>"kalle.anka@vonanka.com"
|
45
|
+
# })
|
46
|
+
#
|
47
|
+
# @example Add a coworker from a new coworker
|
48
|
+
# coworker = FruitToLime::Coworker.new
|
49
|
+
# coworker.integration_id = "123"
|
50
|
+
# coworker.first_name="Kalle"
|
51
|
+
# coworker.last_name="Anka"
|
52
|
+
# coworker.email = "kalle.anka@vonanka.com"
|
53
|
+
# rootmodel.add_coworker(coworker)
|
54
|
+
#
|
55
|
+
# @example If you want to keep adding coworkers and dont care about duplicates not being added
|
56
|
+
# begin
|
57
|
+
# rootmodel.add_coworker(coworker)
|
58
|
+
# rescue FruitToLime::AlreadyAddedError
|
59
|
+
# puts "Warning: already added coworker"
|
60
|
+
# end
|
61
|
+
# @see Coworker
|
62
|
+
def add_coworker(coworker)
|
63
|
+
@coworkers = [] if @coworkers == nil
|
64
|
+
|
65
|
+
if coworker == nil
|
66
|
+
raise "Missing coworker to add!"
|
67
|
+
end
|
68
|
+
|
69
|
+
coworker = Coworker.new(coworker) if !coworker.is_a?(Coworker)
|
70
|
+
|
71
|
+
if find_coworker_by_integration_id(coworker.integration_id) != nil
|
72
|
+
raise AlreadyAddedError, "Already added a coworker with integration_id #{coworker.integration_id}"
|
73
|
+
end
|
74
|
+
|
75
|
+
@coworkers.push(coworker)
|
76
|
+
|
77
|
+
return coworker
|
78
|
+
end
|
79
|
+
|
80
|
+
# Adds the specifed organization object to the model.
|
81
|
+
# @example Add an organization from a hash
|
82
|
+
# rootmodel.add_organization({
|
83
|
+
# :integration_id => "123",
|
84
|
+
# :name => "Beagle Boys",
|
85
|
+
# })
|
86
|
+
#
|
87
|
+
# @example Add an organization from a new organization
|
88
|
+
# organization = FruitToLime::Organization.new
|
89
|
+
# organization.integration_id = "123"
|
90
|
+
# organization.name = "Beagle Boys"
|
91
|
+
# rootmodel.add_organization(organization)
|
92
|
+
#
|
93
|
+
# @example If you want to keep adding organizations and dont
|
94
|
+
# care about duplicates not being added. Your model might not
|
95
|
+
# be saved due to duplicate integration_ids.
|
96
|
+
# begin
|
97
|
+
# rootmodel.add_organization(organization)
|
98
|
+
# rescue FruitToLime::AlreadyAddedError
|
99
|
+
# puts "Warning: already added organization"
|
100
|
+
# end
|
101
|
+
# @see Coworker
|
102
|
+
def add_organization(organization)
|
103
|
+
@organizations = [] if @organizations.nil?
|
104
|
+
|
105
|
+
if organization.nil?
|
106
|
+
raise "Missing organization to add"
|
107
|
+
end
|
108
|
+
|
109
|
+
organization = Organization.new(organization) if !organization.is_a?(Organization)
|
110
|
+
|
111
|
+
if find_organization_by_integration_id(organization.integration_id) != nil
|
112
|
+
raise AlreadyAddedError, "Already added an organization with integration_id #(organization.integration_id)"
|
113
|
+
end
|
114
|
+
|
115
|
+
@organizations.push(organization)
|
116
|
+
|
117
|
+
return organization
|
118
|
+
end
|
119
|
+
|
120
|
+
# Adds the specifed deal object to the model.
|
121
|
+
# @example Add an deal from a hash
|
122
|
+
# rootmodel.add_deal({
|
123
|
+
# :integration_id => "123",
|
124
|
+
# :name => "Big deal",
|
125
|
+
# })
|
126
|
+
#
|
127
|
+
# @example Add a deal from a new deal
|
128
|
+
# deal = FruitToLime::Deal.new
|
129
|
+
# deal.integration_id = "123"
|
130
|
+
# deal.name = "Big deal"
|
131
|
+
# rootmodel.add_deal(deal)
|
132
|
+
#
|
133
|
+
# @example If you want to keep adding deals and dont
|
134
|
+
# care about duplicates not being added. Your model might not
|
135
|
+
# be saved due to duplicate integration_ids.
|
136
|
+
# begin
|
137
|
+
# rootmodel.add_deal(deal)
|
138
|
+
# rescue FruitToLime::AlreadyAddedError
|
139
|
+
# puts "Warning: already added deal"
|
140
|
+
# end
|
141
|
+
# @see Coworker
|
142
|
+
def add_deal(deal)
|
143
|
+
@deals = [] if @deals.nil?
|
144
|
+
|
145
|
+
if deal.nil?
|
146
|
+
raise "Missing deal to add"
|
147
|
+
end
|
148
|
+
|
149
|
+
deal = Deal.new(deal) if !deal.is_a?(Deal)
|
150
|
+
|
151
|
+
if find_deal_by_integration_id(deal.integration_id) != nil
|
152
|
+
raise AlreadyAddedError, "Already added a deal with integration_id #{deal.integration_id}"
|
153
|
+
end
|
154
|
+
|
155
|
+
if deal.responsible_coworker.nil?
|
156
|
+
deal.responsible_coworker = @import_coworker
|
157
|
+
end
|
158
|
+
|
159
|
+
@deals.push(deal)
|
160
|
+
|
161
|
+
return deal
|
162
|
+
end
|
163
|
+
|
164
|
+
# Adds the specifed note object to the model.
|
165
|
+
# @example Add an deal from a hash
|
166
|
+
# rootmodel.add_note({
|
167
|
+
# :integration_id => "123",
|
168
|
+
# :text => "This is a note",
|
169
|
+
# })
|
170
|
+
#
|
171
|
+
# @example Add a note from a new note
|
172
|
+
# note = FruitToLime::Note.new
|
173
|
+
# note.integration_id = "123"
|
174
|
+
# note.text = "Big deal"
|
175
|
+
# rootmodel.add_note(note)
|
176
|
+
#
|
177
|
+
# @example If you want to keep adding deals and dont
|
178
|
+
# care about duplicates not being added. Your model might not
|
179
|
+
# be saved due to duplicate integration_ids.
|
180
|
+
# begin
|
181
|
+
# rootmodel.add_deal(deal)
|
182
|
+
# rescue FruitToLime::AlreadyAddedError
|
183
|
+
# puts "Warning: already added deal"
|
184
|
+
# end
|
185
|
+
# @see Coworker
|
186
|
+
def add_note(note)
|
187
|
+
@notes = [] if @notes == nil
|
188
|
+
|
189
|
+
if note.nil?
|
190
|
+
raise "Missing note to add"
|
191
|
+
end
|
192
|
+
|
193
|
+
note = Note.new(note) if !note.is_a?(Note)
|
194
|
+
|
195
|
+
if (!note.integration_id.nil? && note.integration_id.length > 0) &&
|
196
|
+
find_note_by_integration_id(note.integration_id) != nil
|
197
|
+
raise AlreadyAddedError, "Already added a note with integration_id #{note.integration_id}"
|
198
|
+
end
|
199
|
+
|
200
|
+
@notes.push(note)
|
201
|
+
|
202
|
+
return note
|
203
|
+
end
|
204
|
+
|
205
|
+
def with_new_note
|
206
|
+
@notes = [] if @notes == nil
|
207
|
+
|
208
|
+
note = Note.new
|
209
|
+
@notes.push note
|
210
|
+
yield note
|
211
|
+
end
|
212
|
+
|
213
|
+
def find_coworker_by_integration_id(integration_id)
|
214
|
+
return @coworkers.find do |coworker|
|
215
|
+
coworker.integration_id == integration_id
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def find_organization_by_integration_id(integration_id)
|
220
|
+
return @organizations.find do |organization|
|
221
|
+
organization.integration_id == integration_id
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def find_person_by_integration_id(integration_id)
|
226
|
+
return nil if @organizations.nil?
|
227
|
+
@organizations.each do |organization|
|
228
|
+
person = organization.find_employee_by_integration_id(integration_id)
|
229
|
+
return person if person
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def find_note_by_integration_id(integration_id)
|
234
|
+
return @notes.find do |note|
|
235
|
+
note.integration_id == integration_id
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
# find deals for organization using {Organization#integration_id}
|
240
|
+
def find_deals_for_organization(organization)
|
241
|
+
deals = []
|
242
|
+
|
243
|
+
deals = @deals.select do |deal|
|
244
|
+
!deal.customer.nil? && deal.customer.integration_id == organization.integration_id
|
245
|
+
end
|
246
|
+
|
247
|
+
return deals
|
248
|
+
end
|
249
|
+
|
250
|
+
def find_deal_by_integration_id(integration_id)
|
251
|
+
return @deals.find do |deal|
|
252
|
+
deal.integration_id == integration_id
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
# Returns a string describing problems with the data. For instance if integration_id for any entity is not unique.
|
257
|
+
def sanity_check
|
258
|
+
error = String.new
|
259
|
+
|
260
|
+
dups = get_integration_id_duplicates(with_non_empty_integration_id(@coworkers))
|
261
|
+
dups_error_items = (dups.collect{|coworker| coworker.integration_id}).compact
|
262
|
+
if dups.length > 0
|
263
|
+
error = "#{error}\nDuplicate coworker integration_id: #{dups_error_items.join(", ")}."
|
264
|
+
end
|
265
|
+
|
266
|
+
dups = get_integration_id_duplicates(with_non_empty_integration_id(@organizations))
|
267
|
+
dups_error_items = (dups.collect{|org| org.integration_id}).compact
|
268
|
+
if dups.length > 0
|
269
|
+
error = "#{error}\nDuplicate organization integration_id: #{dups_error_items.join(", ")}."
|
270
|
+
end
|
271
|
+
|
272
|
+
dups = get_integration_id_duplicates(with_non_empty_integration_id(@deals))
|
273
|
+
dups_error_items = (dups.collect{|deal| deal.integration_id}).compact
|
274
|
+
if dups_error_items.length > 0
|
275
|
+
error = "#{error}\nDuplicate deal integration_id: #{dups_error_items.join(", ")}."
|
276
|
+
end
|
277
|
+
|
278
|
+
persons = @organizations.collect{|o| o.employees}.flatten.compact
|
279
|
+
dups = get_integration_id_duplicates(with_non_empty_integration_id(persons))
|
280
|
+
dups_error_items = (dups.collect{|person| person.integration_id}).compact
|
281
|
+
if dups_error_items.length > 0
|
282
|
+
error = "#{error}\nDuplicate person integration_id: #{dups_error_items.join(", ")}."
|
283
|
+
end
|
284
|
+
|
285
|
+
return error.strip
|
286
|
+
end
|
287
|
+
|
288
|
+
def validate()
|
289
|
+
error = String.new
|
290
|
+
|
291
|
+
@organizations.each do |o|
|
292
|
+
validation_message = o.validate()
|
293
|
+
|
294
|
+
if !validation_message.empty?
|
295
|
+
error = "#{error}\n#{validation_message}"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
@deals.each do |deal|
|
300
|
+
validation_message = deal.validate
|
301
|
+
|
302
|
+
if !validation_message.empty?
|
303
|
+
error = "#{error}\n#{validation_message}"
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
@notes.each do |note|
|
308
|
+
validation_message = note.validate
|
309
|
+
|
310
|
+
if !validation_message.empty?
|
311
|
+
error = "#{error}\n#{validation_message}"
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
return error.strip
|
316
|
+
end
|
317
|
+
|
318
|
+
# @!visibility private
|
319
|
+
def to_rexml(doc)
|
320
|
+
element_name = serialize_name
|
321
|
+
elem = doc.add_element(element_name,{"Version"=>"v2_0"})
|
322
|
+
SerializeHelper::serialize_variables_rexml(elem, self)
|
323
|
+
end
|
324
|
+
|
325
|
+
private
|
326
|
+
# returns all items from the object array with duplicate integration ids.
|
327
|
+
# To get all organizations with the same integration_id use
|
328
|
+
# @example Get all the organization duplicates with the same integration id
|
329
|
+
# rm.get_integration_id_duplicates(rm.organizations)
|
330
|
+
def get_integration_id_duplicates(objects)
|
331
|
+
uniq_items = objects.uniq {|item| item.integration_id}.compact
|
332
|
+
|
333
|
+
return (objects - uniq_items).compact
|
334
|
+
end
|
335
|
+
|
336
|
+
def with_non_empty_integration_id(objects)
|
337
|
+
return objects.select do |obj|
|
338
|
+
obj.integration_id!=nil && !obj.integration_id.empty?
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|