go_import 3.0.5 → 3.0.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.
@@ -380,18 +380,41 @@ module GoImport
380
380
  root_folder = Dir.pwd
381
381
  end
382
382
 
383
+ # If a file's path is absolute, then we probably dont
384
+ # have the files in the same location here. For
385
+ # example, the customer might have stored their files
386
+ # at f:\lime-easy\documents. We must replace this part
387
+ # of each file with the root_folder from above.
388
+ if defined?(FILES_FOLDER_AT_CUSTOMER) && !FILES_FOLDER_AT_CUSTOMER.empty?()
389
+ files_folder_at_customer = FILES_FOLDER_AT_CUSTOMER
390
+ puts "Files with absolute paths will have the part '#{files_folder_at_customer}' replaced with '#{root_folder}'."
391
+ else
392
+ files_folder_at_customer = ""
393
+ puts "Files with absolute paths will be imported from their origial location."
394
+ end
395
+
383
396
  # 1) files/ - a folder with all files referenced from
384
397
  # the source.
385
398
  documents.files.each do |file|
386
399
  # we dont need to check that the file exists since
387
400
  # we assume that rootmodel.validate has been
388
401
  # called before save_to_zip.
402
+ puts "file.path: #{file.path}, relative: #{file.has_relative_path?}"
389
403
  if file.has_relative_path?
390
404
  file.location_in_zip_file = "files/#{file.path}"
391
405
  zip_file.add(file.location_in_zip_file, "#{root_folder}/#{file.path}")
392
406
  else
407
+ puts "ABS!"
408
+ puts files_folder_at_customer
393
409
  file.location_in_zip_file = "files/__abs/#{SecureRandom.uuid}/#{::File.basename(file.path).to_s}"
394
- zip_file.add(file.location_in_zip_file, file.path)
410
+ if files_folder_at_customer.empty?
411
+ zip_file.add(file.location_in_zip_file, file.path)
412
+ else
413
+ puts "file.path.downcase.sub(files_folder_at_customer.downcase, root_folder): "
414
+ puts file.path.downcase.sub(files_folder_at_customer.downcase, root_folder)
415
+ zip_file.add(file.location_in_zip_file,
416
+ file.path.downcase.sub(files_folder_at_customer.downcase, root_folder))
417
+ end
395
418
  end
396
419
  end
397
420
 
@@ -15,6 +15,22 @@ require 'dbf'
15
15
  # Generate the xml-file that should be sent to LIME Go with the command:
16
16
  # go-import run
17
17
 
18
+ # If you are importing files then you must set the FILES_FOLDER
19
+ # constant. FILES_FOLDER should point to the folder where the files
20
+ # are stored. FILES_FOLDER can be relative to the project directory
21
+ # or absolute. Note that you need to escape \ with a \ so in order to
22
+ # write \ use \\.
23
+ FILES_FOLDER = "./files"
24
+
25
+ # If you are importing files with an absolute path (eg
26
+ # m:\documents\readme.doc) then you probably wont have files at that
27
+ # location on the computer where "go-import run" is executed. Set
28
+ # FILES_FOLDER_AT_CUSTOMER to the folder where documents are stored at
29
+ # the customers site. Ie, in this example m:\documents.
30
+ # Note that you need to escape \ with a \ so in order to write \ use
31
+ # \\.
32
+ FILES_FOLDER_AT_CUSTOMER = "m:\\documents\\"
33
+
18
34
  class Converter
19
35
  def configure(rootmodel)
20
36
  # Add custom field to your model here. Custom fields can be
@@ -15,6 +15,22 @@ DEAL_FILE = "data/deals.csv"
15
15
 
16
16
  # Ie if you dont want to import deals, set DEAL_FILE = ""
17
17
 
18
+ # If you are importing files then you must set the FILES_FOLDER
19
+ # constant. FILES_FOLDER should point to the folder where the files
20
+ # are stored. FILES_FOLDER can be relative to the project directory
21
+ # or absolute. Note that you need to escape \ with a \ so in order to
22
+ # write \ use \\.
23
+ FILES_FOLDER = "./files"
24
+
25
+ # If you are importing files with an absolute path (eg
26
+ # m:\documents\readme.doc) then you probably wont have files at that
27
+ # location on the computer where "go-import run" is executed. Set
28
+ # FILES_FOLDER_AT_CUSTOMER to the folder where documents are stored at
29
+ # the customers site. Ie, in this example m:\documents.
30
+ # Note that you need to escape \ with a \ so in order to write \ use
31
+ # \\.
32
+ FILES_FOLDER_AT_CUSTOMER = "m:\\documents\\"
33
+
18
34
  class Converter
19
35
  # Configure your root model, add custom fields and deal statuses.
20
36
  def configure(rootmodel)
@@ -16,6 +16,22 @@ require 'go_import'
16
16
  #
17
17
  # Good luck.
18
18
 
19
+ # If you are importing files then you must set the FILES_FOLDER
20
+ # constant. FILES_FOLDER should point to the folder where the files
21
+ # are stored. FILES_FOLDER can be relative to the project directory
22
+ # or absolute. Note that you need to escape \ with a \ so in order to
23
+ # write \ use \\.
24
+ FILES_FOLDER = "./files"
25
+
26
+ # If you are importing files with an absolute path (eg
27
+ # m:\documents\readme.doc) then you probably wont have files at that
28
+ # location on the computer where "go-import run" is executed. Set
29
+ # FILES_FOLDER_AT_CUSTOMER to the folder where documents are stored at
30
+ # the customers site. Ie, in this example m:\documents.
31
+ # Note that you need to escape \ with a \ so in order to write \ use
32
+ # \\.
33
+ FILES_FOLDER_AT_CUSTOMER = "m:\\documents\\"
34
+
19
35
  class Converter
20
36
  def to_go()
21
37
  rootmodel = GoImport::RootModel.new
@@ -12,6 +12,7 @@ PERSON_FILE = "#{EXPORT_FOLDER}/Company-Person.txt"
12
12
  INCLUDE_FILE = "#{EXPORT_FOLDER}/Project-Included.txt"
13
13
  DEAL_FILE = "#{EXPORT_FOLDER}/Project.txt"
14
14
  DEAL_NOTE_FILE = "#{EXPORT_FOLDER}/Project-History.txt"
15
+ PROJECT_DOCUMENT_FILE = "#{EXPORT_FOLDER}/Project-Document.txt"
15
16
 
16
17
  def convert_source
17
18
  puts "Trying to convert LIME Easy source to LIME Go..."
@@ -28,22 +29,18 @@ def convert_source
28
29
 
29
30
  converter.configure rootmodel
30
31
 
31
- coworkers = Hash.new
32
32
  includes = Hash.new
33
- people = Hash.new
34
33
 
35
34
  # coworkers
36
35
  # start with these since they are referenced
37
36
  # from everywhere....
38
37
  process_rows COWORKER_FILE do |row|
39
- coworkers[row['idUser']] = row['PowerSellUserID']
40
-
41
38
  rootmodel.add_coworker(to_coworker(row))
42
39
  end
43
40
 
44
41
  # organizations
45
42
  process_rows ORGANIZATION_FILE do |row|
46
- organization = init_organization(row)
43
+ organization = init_organization(row, rootmodel)
47
44
  rootmodel.add_organization(
48
45
  converter.to_organization(organization, row))
49
46
  end
@@ -51,7 +48,6 @@ def convert_source
51
48
  # persons
52
49
  # depends on organizations
53
50
  process_rows PERSON_FILE do |row|
54
- people[row['personIndex']] = "#{row['PowerSellReferenceID']}-#{row['PowerSellCompanyID']}"
55
51
  # init method also adds the person to the employer
56
52
  person = init_person(row, rootmodel)
57
53
  converter.to_person(person, row)
@@ -60,14 +56,14 @@ def convert_source
60
56
  # organization notes
61
57
  process_rows ORGANIZATION_NOTE_FILE do |row|
62
58
  # adds itself if applicable
63
- rootmodel.add_note(to_organization_note(row, coworkers, people, rootmodel))
59
+ rootmodel.add_note(to_organization_note(row, rootmodel))
64
60
  end
65
61
 
66
62
  # Organization - Deal connection
67
63
  # Reads the includes.txt and creats a hash
68
64
  # that connect organizations to deals
69
65
  process_rows INCLUDE_FILE do |row|
70
- includes[row['PowerSellProjectID']] = row['PowerSellCompanyID']
66
+ includes[row['idProject']] = row['idCompany']
71
67
  end
72
68
 
73
69
  # deals
@@ -81,17 +77,19 @@ def convert_source
81
77
  # deal notes
82
78
  process_rows DEAL_NOTE_FILE do |row|
83
79
  # adds itself if applicable
84
- rootmodel.add_note(to_deal_note(row, coworkers, rootmodel))
80
+ rootmodel.add_note(to_deal_note(row, rootmodel))
85
81
  end
86
82
 
87
83
  # company documents
88
84
  if defined?(IMPORT_DOCUMENTS) && !IMPORT_DOCUMENTS.nil? && IMPORT_DOCUMENTS
89
85
  process_rows ORGANIZATION_DOCUMENT_FILE do |row|
90
- rootmodel.add_file(to_organization_document(row, coworkers, rootmodel))
86
+ rootmodel.add_file(to_organization_document(row, rootmodel))
91
87
  end
92
- end
93
-
94
88
 
89
+ process_rows PROJECT_DOCUMENT_FILE do |row|
90
+ rootmodel.add_file(from_project_document_to_organization_document(row, rootmodel))
91
+ end
92
+ end
95
93
  return rootmodel
96
94
  end
97
95
 
@@ -100,17 +98,17 @@ def to_coworker(row)
100
98
  # integration_id is typically the userId in Easy
101
99
  # Must be set to be able to import the same file more
102
100
  # than once without creating duplicates
103
- coworker.integration_id = row['PowerSellUserID']
101
+ coworker.integration_id = row['idUser']
104
102
  coworker.parse_name_to_firstname_lastname_se(row['Name'])
105
103
  return coworker
106
104
  end
107
105
 
108
- def init_organization(row)
106
+ def init_organization(row, rootmodel)
109
107
  organization = GoImport::Organization.new
110
108
  # integration_id is typically the company Id in Easy
111
109
  # Must be set to be able to import the same file more
112
110
  # than once without creating duplicates
113
- organization.integration_id = row['PowerSellCompanyID']
111
+ organization.integration_id = row['idCompany']
114
112
 
115
113
  # Easy standard fields
116
114
  organization.name = row['Company name']
@@ -119,7 +117,7 @@ def init_organization(row)
119
117
  if defined?(ORGANIZATION_RESPONSIBLE_FIELD) && !ORGANIZATION_RESPONSIBLE_FIELD.nil? && !ORGANIZATION_RESPONSIBLE_FIELD.empty?
120
118
  # Responsible coworker for the organization.
121
119
  # For instance responsible sales rep.
122
- coworker_id = coworkers[row["idUser-#{ORGANIZATION_RESPONSIBLE_FIELD}"]]
120
+ coworker_id = row["idUser-#{ORGANIZATION_RESPONSIBLE_FIELD}"]
123
121
  organization.responsible_coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
124
122
  end
125
123
 
@@ -134,12 +132,12 @@ def init_person(row, rootmodel)
134
132
  # unique within the scope of the company, so we combine the
135
133
  # referenceId and the companyId to make a globally unique
136
134
  # integration_id
137
- person.integration_id = "#{row['PowerSellReferenceID']}-#{row['PowerSellCompanyID']}"
135
+ person.integration_id = row['idPerson']
138
136
  person.first_name = row['First name']
139
137
  person.last_name = row['Last name']
140
138
 
141
139
  # set employer connection
142
- employer = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
140
+ employer = rootmodel.find_organization_by_integration_id(row['idCompany'])
143
141
  if employer
144
142
  employer.add_employee person
145
143
  end
@@ -149,19 +147,15 @@ end
149
147
 
150
148
  # Turns a row from the Easy exported Company-History.txt file into
151
149
  # a go_import model that is used to generate xml.
152
- # Uses coworkers hash to lookup coworkers to connect
153
- # Uses people hash to lookup persons to connect
154
- def to_organization_note(row, coworkers, people, rootmodel)
155
- organization = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
156
-
157
- coworker_id = coworkers[row['idUser']]
158
- coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
150
+ def to_organization_note(row, rootmodel)
151
+ organization = rootmodel.find_organization_by_integration_id(row['idCompany'])
152
+ coworker = rootmodel.find_coworker_by_integration_id(row['idUser'])
159
153
 
160
154
  if organization && coworker
161
155
  note = GoImport::Note.new()
162
156
  note.organization = organization
163
157
  note.created_by = coworker
164
- note.person = organization.find_employee_by_integration_id(people[row['idPerson']])
158
+ note.person = organization.find_employee_by_integration_id(row['idPerson'])
165
159
  note.date = row['Date']
166
160
  note.text = "#{row['Category']}: #{row['History']}"
167
161
 
@@ -171,35 +165,47 @@ def to_organization_note(row, coworkers, people, rootmodel)
171
165
  return nil
172
166
  end
173
167
 
174
- def to_organization_document(row, coworkers, rootmodel)
168
+ def to_organization_document(row, rootmodel)
175
169
  file = GoImport::File.new()
176
170
 
177
- file.integration_id = row['PowerSellDocumentID']
171
+ file.integration_id = "o-#{row['idDocument']}"
178
172
  file.path = row['Path']
179
173
  file.name = row['Comment']
180
174
 
181
- coworker_id = coworkers[row['idUser-Created']]
182
- file.created_by = rootmodel.find_coworker_by_integration_id(coworker_id)
183
- file.organization = rootmodel.find_organization_by_integration_id(row['PowerSellCompanyID'])
175
+ file.created_by = rootmodel.find_coworker_by_integration_id(row['idUser-Created'])
176
+ file.organization = rootmodel.find_organization_by_integration_id(row['idCompany'])
184
177
 
185
178
  return file
186
179
  end
187
180
 
181
+ def from_project_document_to_organization_document(row, includes, rootmodel)
182
+ file = GoImport::File.new()
183
+
184
+ file.integration_id = "d-#{row['idDocument']}"
185
+ file.path = row['Path']
186
+ file.name = row['Comment']
187
+
188
+ file.created_by = rootmodel.find_coworker_by_integration_id(row['idUser-Created'])
189
+
190
+ organization_id = includes[row['idProject']]
191
+ file.organization = rootmodel.find_organization_by_integration_id(organization_id)
192
+ end
193
+
188
194
  def init_deal(row, rootmodel, includes)
189
195
  deal = GoImport::Deal.new
190
196
 
191
- deal.integration_id = row['PowerSellProjectID']
197
+ deal.integration_id = row['idProject']
192
198
  deal.name = row['Name']
193
199
  deal.description = row['Description']
194
200
 
195
201
  if defined?(DEAL_RESPONSIBLE_FIELD) && !DEAL_RESPONSIBLE_FIELD.nil? && !DEAL_RESPONSIBLE_FIELD.empty?
196
- coworker_id = coworkers[row["isUser-#{DEAL_RESPONSIBLE_FIELD}"]]
202
+ coworker_id = row["isUser-#{DEAL_RESPONSIBLE_FIELD}"]
197
203
  deal.responsible_coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
198
204
  end
199
205
 
200
206
  # Make the deal - organization connection
201
207
  if includes
202
- organization_id = includes[row['PowerSellProjectID']]
208
+ organization_id = includes[row['idProject']]
203
209
  organization = rootmodel.find_organization_by_integration_id(organization_id)
204
210
  if organization
205
211
  deal.customer = organization
@@ -211,16 +217,13 @@ end
211
217
 
212
218
  # Turns a row from the Easy exported Project-History.txt file into
213
219
  # a go_import model that is used to generate xml
214
- # Uses coworkers hash to lookup coworkers to connect
215
- def to_deal_note(row, coworkers, rootmodel)
220
+ def to_deal_note(row, rootmodel)
216
221
  # TODO: This could be improved to read a person from an
217
222
  # organization connected to this deal if any, but since it is
218
223
  # a many to many connection between organizations and deals
219
224
  # it's not a straight forward task
220
- deal = rootmodel.find_deal_by_integration_id(row['PowerSellProjectID'])
221
-
222
- coworker_id = coworkers[row['idUser']]
223
- coworker = rootmodel.find_coworker_by_integration_id(coworker_id)
225
+ deal = rootmodel.find_deal_by_integration_id(row['idProject'])
226
+ coworker = rootmodel.find_coworker_by_integration_id(row['idUser'])
224
227
 
225
228
  if deal && coworker
226
229
  note = GoImport::Note.new()
@@ -280,5 +283,6 @@ def make_sure_database_has_been_exported()
280
283
  File.exists?(PERSON_FILE) &&
281
284
  File.exists?(INCLUDE_FILE) &&
282
285
  File.exists?(DEAL_FILE) &&
283
- File.exists?(DEAL_NOTE_FILE)
286
+ File.exists?(DEAL_NOTE_FILE) &&
287
+ File.exists?(PROJECT_DOCUMENT_FILE)
284
288
  end
@@ -48,6 +48,21 @@ require 'go_import'
48
48
  # set the name of the deal-responsible field.
49
49
  # DEAL_RESPONSIBLE_FIELD = "Responsible"
50
50
 
51
+ # If you are importing files then you must set the FILES_FOLDER
52
+ # constant. FILES_FOLDER should point to the folder where the files
53
+ # are stored. FILES_FOLDER can be relative to the project directory
54
+ # or absolute. Note that you need to escape \ with a \ so in order to
55
+ # write \ use \\.
56
+ FILES_FOLDER = "./files"
57
+
58
+ # If you are importing files with an absolute path (eg
59
+ # m:\documents\readme.doc) then you probably wont have files at that
60
+ # location on the computer where "go-import run" is executed. Set
61
+ # FILES_FOLDER_AT_CUSTOMER to the folder where documents are stored at
62
+ # the customers site. Ie, in this example m:\documents.
63
+ # Note that you need to escape \ with a \ so in order to write \ use
64
+ # \\.
65
+ FILES_FOLDER_AT_CUSTOMER = "m:\\documents\\"
51
66
 
52
67
  class Converter
53
68
  # Reads a row from the Easy exported Company.txt
@@ -25,8 +25,21 @@ FILE_SHEET = "Dokument"
25
25
  # command:
26
26
  # go-import run
27
27
 
28
- # If you want to include any file in the import.
29
- FILES_FOLDER = "D:\\go-import\\file-test\\files"
28
+ # If you are importing files then you must set the FILES_FOLDER
29
+ # constant. FILES_FOLDER should point to the folder where the files
30
+ # are stored. FILES_FOLDER can be relative to the project directory
31
+ # or absolute. Note that you need to escape \ with a \ so in order to
32
+ # write \ use \\.
33
+ FILES_FOLDER = "./files"
34
+
35
+ # If you are importing files with an absolute path (eg
36
+ # m:\documents\readme.doc) then you probably wont have files at that
37
+ # location on the computer where "go-import run" is executed. Set
38
+ # FILES_FOLDER_AT_CUSTOMER to the folder where documents are stored at
39
+ # the customers site. Ie, in this example m:\documents.
40
+ # Note that you need to escape \ with a \ so in order to write \ use
41
+ # \\.
42
+ FILES_FOLDER_AT_CUSTOMER = "m:\\documents\\"
30
43
 
31
44
  class Converter
32
45
  def configure(rootmodel)
data/spec/file_spec.rb CHANGED
@@ -8,7 +8,7 @@ describe "File" do
8
8
 
9
9
  it "is valid when it has path, created_by and organization" do
10
10
  # given
11
- file.path = "spec\\sample_data\\offert.docx"
11
+ file.path = "spec/sample_data/offert.docx"
12
12
  file.created_by = GoImport::CoworkerReference.new( { :integration_id => "123" } )
13
13
  file.organization = GoImport::OrganizationReference.new( { :integration_id => "456" } )
14
14
 
@@ -19,7 +19,7 @@ describe "File" do
19
19
  it "is valid when it has name, path, created_by and deal" do
20
20
  # given
21
21
  file.name = "Offert"
22
- file.path = "spec\\sample_data\\offert.docx"
22
+ file.path = "spec/sample_data/offert.docx"
23
23
  file.created_by = GoImport::CoworkerReference.new( { :integration_id => "123" } )
24
24
  file.deal = GoImport::DealReference.new( { :integration_id => "456" } )
25
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_import
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-09-24 00:00:00.000000000 Z
15
+ date: 2014-10-02 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: iso_country_codes