go_import 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/go-import +96 -0
- data/lib/go_import/csv_helper.rb +47 -0
- data/lib/go_import/email_helper.rb +10 -0
- data/lib/go_import/errors.rb +22 -0
- data/lib/go_import/excel_helper.rb +10 -0
- data/lib/go_import/global_phone.json +6571 -0
- data/lib/go_import/model/address.rb +61 -0
- data/lib/go_import/model/class_settings.rb +50 -0
- data/lib/go_import/model/coworker.rb +76 -0
- data/lib/go_import/model/coworker_reference.rb +33 -0
- data/lib/go_import/model/customfield.rb +87 -0
- data/lib/go_import/model/deal.rb +172 -0
- data/lib/go_import/model/deal_class_settings.rb +73 -0
- data/lib/go_import/model/deal_state.rb +15 -0
- data/lib/go_import/model/deal_status.rb +23 -0
- data/lib/go_import/model/deal_status_reference.rb +47 -0
- data/lib/go_import/model/deal_status_setting.rb +49 -0
- data/lib/go_import/model/documents.rb +51 -0
- data/lib/go_import/model/link.rb +70 -0
- data/lib/go_import/model/note.rb +97 -0
- data/lib/go_import/model/note_classification.rb +25 -0
- data/lib/go_import/model/organization.rb +219 -0
- data/lib/go_import/model/person.rb +151 -0
- data/lib/go_import/model/referencetosource.rb +46 -0
- data/lib/go_import/model/relation.rb +23 -0
- data/lib/go_import/model/rootmodel.rb +359 -0
- data/lib/go_import/model/settings.rb +61 -0
- data/lib/go_import/model/tag.rb +35 -0
- data/lib/go_import/model_helpers.rb +54 -0
- data/lib/go_import/phone_helper.rb +74 -0
- data/lib/go_import/roo_helper.rb +80 -0
- data/lib/go_import/serialize_helper.rb +186 -0
- data/lib/go_import/source.rb +87 -0
- data/lib/go_import/templating.rb +52 -0
- data/lib/go_import.rb +19 -0
- data/sources/csv/.gitignore +14 -0
- data/sources/csv/.go_import/runner.rb +62 -0
- data/sources/csv/Gemfile +5 -0
- data/sources/csv/Rakefile.rb +7 -0
- data/sources/csv/converter.rb +179 -0
- data/sources/csv/data/coworkers.csv +2 -0
- data/sources/csv/data/deals.csv +2 -0
- data/sources/csv/data/organizations.csv +2 -0
- data/sources/csv/data/persons.csv +2 -0
- data/sources/csv/spec/exporter_spec.rb +17 -0
- data/sources/csv/spec/sample_data/coworkers.csv +2 -0
- data/sources/csv/spec/sample_data/deals.csv +2 -0
- data/sources/csv/spec/sample_data/organizations.csv +2 -0
- data/sources/csv/spec/sample_data/persons.csv +2 -0
- data/sources/csv/spec/spec_helper.rb +30 -0
- data/sources/easy/.gitignore +14 -0
- data/sources/easy/.go_import/runner.rb +115 -0
- data/sources/easy/Export/readme.txt +6 -0
- data/sources/easy/Gemfile +5 -0
- data/sources/easy/Rakefile.rb +7 -0
- data/sources/easy/converter.rb +435 -0
- data/sources/easy/spec/exporter_spec.rb +10 -0
- data/sources/easy/spec/sample_data/Company.txt +649 -0
- data/sources/easy/spec/spec_helper.rb +30 -0
- data/sources/excel/.gitignore +14 -0
- data/sources/excel/.go_import/runner.rb +116 -0
- data/sources/excel/Gemfile +6 -0
- data/sources/excel/Rakefile.rb +7 -0
- data/sources/excel/converter.rb +130 -0
- data/sources/excel/spec/sample_data/sample.xlsx +0 -0
- data/sources/excel/spec/spec_helper.rb +26 -0
- data/sources/excel/spec/tomodel_spec.rb +18 -0
- data/sources/excel/template.xlsx +0 -0
- data/spec/address_spec.rb +49 -0
- data/spec/class_settings_spec.rb +37 -0
- data/spec/coworker_spec.rb +94 -0
- data/spec/custom_field_spec.rb +22 -0
- data/spec/deal_class_settings_spec.rb +104 -0
- data/spec/deal_spec.rb +182 -0
- data/spec/deal_status_reference_spec.rb +17 -0
- data/spec/documents_spec.rb +37 -0
- data/spec/helpers/csv_helper_spec.rb +29 -0
- data/spec/helpers/email_helper_spec.rb +32 -0
- data/spec/helpers/phone_helper_spec.rb +97 -0
- data/spec/helpers/roo_helper_spec.rb +10 -0
- data/spec/helpers/serialize_helper_spec.rb +249 -0
- data/spec/helpers/xsd_validate_spec.rb +55 -0
- data/spec/link_spec.rb +106 -0
- data/spec/note_spec.rb +110 -0
- data/spec/organization_spec.rb +151 -0
- data/spec/person_spec.rb +132 -0
- data/spec/rootmodel_spec.rb +371 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/templating_spec.rb +12 -0
- metadata +306 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module GoImport
|
3
|
+
# This class is the container for all documents, ie links and
|
4
|
+
# files.
|
5
|
+
class Documents
|
6
|
+
# *** TODO: add files when supported by the backend.
|
7
|
+
|
8
|
+
include SerializeHelper
|
9
|
+
|
10
|
+
attr_accessor :links
|
11
|
+
|
12
|
+
def serialize_variables
|
13
|
+
[
|
14
|
+
{:id => :links, @type => :links}
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def serialize_name
|
19
|
+
"Documents"
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@links = []
|
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
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module GoImport
|
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, :type => :coworker_reference },
|
30
|
+
{ :id => :organization, :type => :organization_reference },
|
31
|
+
{ :id => :deal, :type => :deal_reference }
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
def organization=(org)
|
36
|
+
@organization = OrganizationReference.from_organization(org)
|
37
|
+
end
|
38
|
+
|
39
|
+
def deal=(deal)
|
40
|
+
@deal = DealReference.from_deal(deal)
|
41
|
+
end
|
42
|
+
|
43
|
+
def created_by=(coworker)
|
44
|
+
@created_by = CoworkerReference.from_coworker(coworker)
|
45
|
+
end
|
46
|
+
|
47
|
+
def validate
|
48
|
+
error = String.new
|
49
|
+
|
50
|
+
if @url.nil? || @url.empty?
|
51
|
+
error = "Url is required for link\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
if @created_by.nil?
|
55
|
+
error = "#{error}Created_by is required for link\n"
|
56
|
+
end
|
57
|
+
|
58
|
+
if @organization.nil? && @deal.nil?
|
59
|
+
error = "#{error}A link must have either an organization or a deal\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
if !@organization.nil? && !@deal.nil?
|
63
|
+
error = "#{error}A link can't be attached to both an organization and a deal"
|
64
|
+
end
|
65
|
+
|
66
|
+
return error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module GoImport
|
2
|
+
class Note
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :id, :text, :integration_id, :date
|
5
|
+
|
6
|
+
attr_reader :organization, :created_by, :person, :deal
|
7
|
+
|
8
|
+
# The note's classification. It should be a value from
|
9
|
+
# {#NoteClassification}. The default value is Comment.
|
10
|
+
attr_reader :classification
|
11
|
+
|
12
|
+
def initialize(opt = nil)
|
13
|
+
if !opt.nil?
|
14
|
+
serialize_variables.each do |myattr|
|
15
|
+
val = opt[myattr[:id]]
|
16
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@classification = NoteClassification::Comment if @classification.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def serialize_variables
|
24
|
+
[ :id, :text, :integration_id, :classification ].map {
|
25
|
+
|p| {
|
26
|
+
:id => p,
|
27
|
+
:type => :string
|
28
|
+
}
|
29
|
+
} +
|
30
|
+
[
|
31
|
+
{ :id => :date, :type => :date },
|
32
|
+
{ :id => :created_by, :type => :coworker_reference },
|
33
|
+
{ :id => :organization, :type => :organization_reference },
|
34
|
+
{ :id => :deal, :type => :deal_reference },
|
35
|
+
{ :id => :person, :type => :person_reference }
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_import_rows
|
40
|
+
(serialize_variables + [
|
41
|
+
{ :id => :organization, :type => :organization_reference},
|
42
|
+
{ :id => :person, :type => :person_reference}
|
43
|
+
]).map do |p|
|
44
|
+
map_to_row p
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def serialize_name
|
49
|
+
"Note"
|
50
|
+
end
|
51
|
+
|
52
|
+
def organization=(org)
|
53
|
+
@organization = OrganizationReference.from_organization(org)
|
54
|
+
end
|
55
|
+
|
56
|
+
def created_by=(coworker)
|
57
|
+
@created_by = CoworkerReference.from_coworker(coworker)
|
58
|
+
end
|
59
|
+
|
60
|
+
def person=(person)
|
61
|
+
@person = PersonReference.from_person(person)
|
62
|
+
end
|
63
|
+
|
64
|
+
def deal=(deal)
|
65
|
+
@deal = DealReference.from_deal(deal)
|
66
|
+
end
|
67
|
+
|
68
|
+
def classification=(classification)
|
69
|
+
if classification == NoteClassification::Comment || classification == NoteClassification::SalesCall ||
|
70
|
+
classification == NoteClassification::TalkedTo || classification == NoteClassification::TriedToReach ||
|
71
|
+
classification == NoteClassification::ClientVisit
|
72
|
+
@classification = classification
|
73
|
+
else
|
74
|
+
raise InvalidNoteClassificationError
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate
|
80
|
+
error = String.new
|
81
|
+
|
82
|
+
if @text.nil? || @text.empty?
|
83
|
+
error = "Text is required for note\n"
|
84
|
+
end
|
85
|
+
|
86
|
+
if @created_by.nil?
|
87
|
+
error = "#{error}Created_by is required for note\n"
|
88
|
+
end
|
89
|
+
|
90
|
+
if @organization.nil? && @deal.nil? && @person.nil?
|
91
|
+
error = "#{error}Organization, deal or person is required for note\n"
|
92
|
+
end
|
93
|
+
|
94
|
+
return error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module GoImport
|
2
|
+
# Defines a note's classification. This defines what kind of
|
3
|
+
# action that happened before the note was written.
|
4
|
+
module NoteClassification
|
5
|
+
# We talked to the client about a sale. This might be a phone call
|
6
|
+
# or a talk in person.
|
7
|
+
SalesCall = 0
|
8
|
+
|
9
|
+
# This is a general comment about the organization or deal.
|
10
|
+
Comment = 1
|
11
|
+
|
12
|
+
# This is a general comment regarding a talk we had with
|
13
|
+
# someone at the client.
|
14
|
+
TalkedTo = 2
|
15
|
+
|
16
|
+
# We tried to reach someone but failed.
|
17
|
+
TriedToReach = 3
|
18
|
+
|
19
|
+
# We had a meeting at the client's site.
|
20
|
+
ClientVisit = 4
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'date'
|
2
|
+
module GoImport
|
3
|
+
class OrganizationReference
|
4
|
+
include SerializeHelper
|
5
|
+
attr_accessor :id, :integration_id, :heading
|
6
|
+
def serialize_variables
|
7
|
+
[ :id, :integration_id, :heading ].map { |prop| {
|
8
|
+
:id => prop, :type => :string
|
9
|
+
}
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(opt = nil)
|
14
|
+
if opt != nil
|
15
|
+
serialize_variables.each do |var|
|
16
|
+
value = opt[var[:id]]
|
17
|
+
instance_variable_set("@" + var[:id].to_s, value) if value != nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
return "(#{id}, #{integration_id}, #{heading})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def empty?
|
27
|
+
return !@integration_id && !@id && !@heading
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.from_organization(organization)
|
31
|
+
if organization.nil?
|
32
|
+
return nil
|
33
|
+
elsif organization.is_a?(Organization)
|
34
|
+
return organization.to_reference
|
35
|
+
elsif organization.is_a?(OrganizationReference)
|
36
|
+
return organization
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Organization
|
42
|
+
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
43
|
+
|
44
|
+
attr_accessor :id, :integration_id, :name, :organization_number, :email, :web_site,
|
45
|
+
:postal_address, :visit_address, :central_phone_number, :source_data
|
46
|
+
|
47
|
+
# Sets/gets the date when this organization's relation was
|
48
|
+
# changed. Default is Now.
|
49
|
+
attr_reader :relation_last_modified
|
50
|
+
|
51
|
+
attr_reader :employees, :responsible_coworker, :relation
|
52
|
+
# you add custom values by using {#set_custom_value}
|
53
|
+
attr_reader :custom_values
|
54
|
+
|
55
|
+
def initialize(opt = nil)
|
56
|
+
if !opt.nil?
|
57
|
+
serialize_variables.each do |myattr|
|
58
|
+
val = opt[myattr[:id]]
|
59
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
@relation = Relation::NoRelation if @relation.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_reference()
|
67
|
+
reference = OrganizationReference.new
|
68
|
+
reference.id = @id
|
69
|
+
reference.integration_id = @integration_id
|
70
|
+
reference.heading = @name
|
71
|
+
return reference
|
72
|
+
end
|
73
|
+
|
74
|
+
def ==(that)
|
75
|
+
if that.nil?
|
76
|
+
return false
|
77
|
+
end
|
78
|
+
|
79
|
+
if that.is_a? Organization
|
80
|
+
return @integration_id == that.integration_id
|
81
|
+
end
|
82
|
+
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
86
|
+
# @example Set city of postal address to 'Lund'
|
87
|
+
# o.with_postal_address do |addr|
|
88
|
+
# addr.city = "Lund"
|
89
|
+
# end
|
90
|
+
# @see Address address
|
91
|
+
def with_postal_address
|
92
|
+
@postal_address = Address.new if @postal_address == nil
|
93
|
+
yield @postal_address
|
94
|
+
end
|
95
|
+
|
96
|
+
# @example Set city of visit address to 'Lund'
|
97
|
+
# o.with_visit_address do |addr|
|
98
|
+
# addr.city = "Lund"
|
99
|
+
# end
|
100
|
+
# @see Address address
|
101
|
+
def with_visit_address
|
102
|
+
@visit_address = Address.new if @visit_address == nil
|
103
|
+
yield @visit_address
|
104
|
+
end
|
105
|
+
|
106
|
+
# @example Set the source to par id 4653
|
107
|
+
# o.with_source do |source|
|
108
|
+
# source.par_se('4653')
|
109
|
+
# end
|
110
|
+
# @see ReferenceToSource source
|
111
|
+
def with_source
|
112
|
+
@source = ReferenceToSource.new if @source == nil
|
113
|
+
yield @source
|
114
|
+
end
|
115
|
+
|
116
|
+
# @example Add an employee and then add additional info to that employee
|
117
|
+
# employee = o.add_employee({
|
118
|
+
# :integration_id => "79654",
|
119
|
+
# :first_name => "Peter",
|
120
|
+
# :last_name => "Wilhelmsson"
|
121
|
+
# })
|
122
|
+
# employee.direct_phone_number = '+234234234'
|
123
|
+
# employee.currently_employed = true
|
124
|
+
# @see Person employee
|
125
|
+
def add_employee(val)
|
126
|
+
@employees = [] if @employees == nil
|
127
|
+
person = if val.is_a? Person then val else Person.new(val) end
|
128
|
+
@employees.push(person)
|
129
|
+
person
|
130
|
+
end
|
131
|
+
|
132
|
+
def responsible_coworker=(coworker)
|
133
|
+
@responsible_coworker = CoworkerReference.from_coworker(coworker)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Sets the organization's relation to the specified value. The
|
137
|
+
# relation must be a valid value from the Relation module
|
138
|
+
# otherwise an InvalidRelationError error will be thrown.
|
139
|
+
def relation=(relation)
|
140
|
+
if relation == Relation::NoRelation || relation == Relation::WorkingOnIt ||
|
141
|
+
relation == Relation::IsACustomer || relation == Relation::WasACustomer || relation == Relation::BeenInTouch
|
142
|
+
@relation = relation
|
143
|
+
@relation_last_modified = Time.now.strftime("%Y-%m-%d") if @relation_last_modified.nil? &&
|
144
|
+
@relation != Relation::NoRelation
|
145
|
+
else
|
146
|
+
raise InvalidRelationError
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def relation_last_modified=(date)
|
151
|
+
begin
|
152
|
+
@relation_last_modified = @relation != Relation::NoRelation ? Date.parse(date).strftime("%Y-%m-%d") : nil
|
153
|
+
rescue
|
154
|
+
raise InvalidValueError, date
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def find_employee_by_integration_id(integration_id)
|
159
|
+
return nil if @employees.nil?
|
160
|
+
return @employees.find do |e|
|
161
|
+
e.integration_id == integration_id
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def serialize_variables
|
166
|
+
[
|
167
|
+
{ :id => :id, :type => :string },
|
168
|
+
{ :id => :integration_id, :type => :string },
|
169
|
+
{ :id => :source, :type => :source_ref },
|
170
|
+
{ :id => :name, :type => :string },
|
171
|
+
{ :id => :organization_number, :type => :string },
|
172
|
+
{ :id => :postal_address, :type => :address },
|
173
|
+
{ :id => :visit_address, :type => :address },
|
174
|
+
{ :id => :central_phone_number, :type => :string },
|
175
|
+
{ :id => :email, :type => :string },
|
176
|
+
{ :id => :web_site, :type => :string },
|
177
|
+
{ :id => :employees, :type => :persons },
|
178
|
+
{ :id => :custom_values, :type => :custom_values },
|
179
|
+
{ :id => :tags, :type => :tags },
|
180
|
+
{ :id => :responsible_coworker, :type => :coworker_reference},
|
181
|
+
{ :id => :relation, :type => :string },
|
182
|
+
{ :id => :relation_last_modified, :type => :string }
|
183
|
+
]
|
184
|
+
end
|
185
|
+
|
186
|
+
def serialize_name
|
187
|
+
"Organization"
|
188
|
+
end
|
189
|
+
|
190
|
+
def to_s
|
191
|
+
return "#{name}"
|
192
|
+
end
|
193
|
+
|
194
|
+
def validate
|
195
|
+
error = String.new
|
196
|
+
|
197
|
+
if @name.nil? || @name.empty?
|
198
|
+
error = "A name is required for organization.\n#{serialize()}"
|
199
|
+
end
|
200
|
+
|
201
|
+
if !@source.nil?
|
202
|
+
if @source.id.nil? || @source.id == ""
|
203
|
+
error = "#{error}\nReference to source must have an id"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
if @employees != nil
|
208
|
+
@employees.each do |person|
|
209
|
+
validation_message = person.validate()
|
210
|
+
if !validation_message.empty?
|
211
|
+
error = "#{error}\n#{validation_message}"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
return error
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
module GoImport
|
2
|
+
class PersonReference
|
3
|
+
include SerializeHelper
|
4
|
+
attr_accessor :id, :integration_id
|
5
|
+
def serialize_variables
|
6
|
+
[ :id, :integration_id ].map { |prop| {:id=>prop,:type=>:string} }
|
7
|
+
end
|
8
|
+
|
9
|
+
def initalize()
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
return "(#{id}, #{integration_id})"
|
14
|
+
end
|
15
|
+
|
16
|
+
def empty?
|
17
|
+
return !@integration_id && !@id
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_person(person)
|
21
|
+
if person.nil?
|
22
|
+
return nil
|
23
|
+
elsif person.is_a?(Person)
|
24
|
+
return person.to_reference
|
25
|
+
elsif person.is_a?(PersonReference)
|
26
|
+
return person
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Person < PersonReference
|
32
|
+
include SerializeHelper, ModelHasCustomFields, ModelHasTags
|
33
|
+
attr_accessor :first_name, :last_name,
|
34
|
+
:direct_phone_number, :fax_phone_number, :mobile_phone_number, :home_phone_number,
|
35
|
+
:position, :email, :alternative_email, :postal_address, :currently_employed
|
36
|
+
|
37
|
+
# you add custom values by using {#set_custom_value}
|
38
|
+
attr_reader :custom_values, :organization
|
39
|
+
|
40
|
+
def initialize(opt = nil)
|
41
|
+
@currently_employed = true
|
42
|
+
if opt != nil
|
43
|
+
serialize_variables.each do |myattr|
|
44
|
+
val = opt[myattr[:id]]
|
45
|
+
instance_variable_set("@" + myattr[:id].to_s, val) if val != nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def organization=(org)
|
51
|
+
@organization = OrganizationReference.from_organization(org)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @example Set city of postal address to 'Lund'
|
55
|
+
# p.with_postal_address do |addr|
|
56
|
+
# addr.city = "Lund"
|
57
|
+
# end
|
58
|
+
# @see Address address
|
59
|
+
def with_postal_address
|
60
|
+
@postal_address = Address.new if @postal_address == nil
|
61
|
+
yield @postal_address
|
62
|
+
end
|
63
|
+
|
64
|
+
# @example Set the source to par id 4653
|
65
|
+
# p.with_source do |source|
|
66
|
+
# source.par_se('4653')
|
67
|
+
# end
|
68
|
+
# @see ReferenceToSource source
|
69
|
+
def with_source
|
70
|
+
@source = ReferenceToSource.new if @source == nil
|
71
|
+
yield @source
|
72
|
+
end
|
73
|
+
|
74
|
+
def tags
|
75
|
+
@tags
|
76
|
+
end
|
77
|
+
|
78
|
+
def serialize_name
|
79
|
+
"Person"
|
80
|
+
end
|
81
|
+
|
82
|
+
def serialize_variables
|
83
|
+
[
|
84
|
+
{:id => :id, :type => :string},
|
85
|
+
{:id => :integration_id, :type => :string},
|
86
|
+
{:id => :source, :type => :source_ref},
|
87
|
+
{:id => :first_name, :type => :string},
|
88
|
+
{:id => :last_name, :type => :string},
|
89
|
+
|
90
|
+
{:id => :direct_phone_number, :type => :string},
|
91
|
+
{:id => :fax_phone_number, :type => :string},
|
92
|
+
{:id => :mobile_phone_number, :type => :string},
|
93
|
+
{:id => :home_phone_number, :type => :string},
|
94
|
+
|
95
|
+
{:id => :position, :type => :string},
|
96
|
+
|
97
|
+
{:id => :tags, :type => :tags},
|
98
|
+
|
99
|
+
{:id => :email, :type => :string},
|
100
|
+
{:id => :alternative_email, :type => :string},
|
101
|
+
|
102
|
+
{:id => :postal_address, :type => :address},
|
103
|
+
{:id => :custom_values, :type => :custom_values},
|
104
|
+
{:id => :currently_employed, :type => :bool},
|
105
|
+
{:id => :organization, :type => :organization_reference},
|
106
|
+
|
107
|
+
]
|
108
|
+
end
|
109
|
+
|
110
|
+
def to_reference()
|
111
|
+
reference = PersonReference.new
|
112
|
+
reference.id = @id
|
113
|
+
reference.integration_id = @integration_id
|
114
|
+
return reference
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_import_rows
|
118
|
+
(serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p|
|
119
|
+
map_to_row p
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_s
|
124
|
+
return "#{first_name} #{last_name}"
|
125
|
+
end
|
126
|
+
|
127
|
+
def validate
|
128
|
+
error = String.new
|
129
|
+
|
130
|
+
if (@first_name.nil? || @first_name.empty?) &&
|
131
|
+
(@last_name.nil? || @last_name.empty?)
|
132
|
+
error = "A firstname or lastname is required for person.\n#{serialize()}"
|
133
|
+
end
|
134
|
+
|
135
|
+
return error
|
136
|
+
end
|
137
|
+
|
138
|
+
def parse_name_to_firstname_lastname_se(name, when_missing = '')
|
139
|
+
if name.nil? or name.empty?
|
140
|
+
@first_name = when_missing
|
141
|
+
return
|
142
|
+
end
|
143
|
+
|
144
|
+
splitted = name.split(' ')
|
145
|
+
@first_name = splitted[0]
|
146
|
+
if splitted.length > 1
|
147
|
+
@last_name = splitted.drop(1).join(' ')
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GoImport
|
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
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GoImport
|
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
|