go_import 3.0.9 → 3.0.10
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/bin/go-import +5 -0
- data/lib/go_import/model/file.rb +65 -20
- data/lib/go_import/model/rootmodel.rb +1 -12
- data/sources/easy/.go_import/runner.rb +2 -0
- data/spec/file_spec.rb +12 -0
- metadata +2 -2
data/bin/go-import
CHANGED
@@ -56,6 +56,11 @@ class GoImportCommandLine < Thor
|
|
56
56
|
puts "WARNING: FILES_FOLDER should be set unless you are only importing files with absolute paths."
|
57
57
|
end
|
58
58
|
|
59
|
+
if model.documents.files.length > 0 && (!defined?(FILES_FOLDER_AT_CUSTOMER) || FILES_FOLDER_AT_CUSTOMER.empty?())
|
60
|
+
puts "WARNING: It looks like you are importing files but FILES_FOLDER_AT_CUSTOMER has not been set in your converter.rb"
|
61
|
+
puts "WARNING: This means that files with an absolute path will be imported with their original path. Set this constant if you want to get files from the FILES_FOLDER directory."
|
62
|
+
end
|
63
|
+
|
59
64
|
is_ok, error_msg = can_be_serialized?(model)
|
60
65
|
if is_ok
|
61
66
|
go_data_zip = options.output.nil? == true ? "go.zip" : options.output
|
data/lib/go_import/model/file.rb
CHANGED
@@ -102,43 +102,88 @@ module GoImport
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
# This is the path to where the file should be accessed
|
106
|
+
# from within the project.
|
107
|
+
def path_for_project
|
108
108
|
if @path.nil? || @path.empty?
|
109
|
-
|
109
|
+
return ""
|
110
|
+
end
|
111
|
+
|
112
|
+
# Get the folder where files should be accessed from
|
113
|
+
# during the import. If not defined in converter.rb use
|
114
|
+
# the current directory
|
115
|
+
if defined?(FILES_FOLDER) && !FILES_FOLDER.empty?()
|
116
|
+
root_folder = FILES_FOLDER
|
117
|
+
else
|
118
|
+
root_folder = Dir.pwd
|
119
|
+
end
|
120
|
+
|
121
|
+
if has_relative_path?()
|
122
|
+
# since this file is stored with a relative file name
|
123
|
+
# we should get it from the root folder
|
124
|
+
path_for_project = ::File.expand_path(@path, root_folder)
|
110
125
|
else
|
111
|
-
if
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
126
|
+
# the file is stored with an absolute path, if the
|
127
|
+
# file cant be access using that path we must change
|
128
|
+
# it to a path that is accessible from this computer.
|
129
|
+
# The FILES_FOLDER_AT_CUSTOMER constant states what
|
130
|
+
# part of the path that should be replaced with the
|
131
|
+
# root folder.
|
132
|
+
|
133
|
+
# We assume that the original system used ONE location
|
134
|
+
# for all its files. If not, we should change
|
135
|
+
# FILES_FOLDER_AT_CUSTOMER to a list of folders.
|
136
|
+
if defined?(FILES_FOLDER_AT_CUSTOMER) && !FILES_FOLDER_AT_CUSTOMER.empty?()
|
137
|
+
files_folder_at_customer = FILES_FOLDER_AT_CUSTOMER
|
121
138
|
else
|
122
|
-
|
123
|
-
error = "#{error}Can't find file '#{@path}'.\n"
|
124
|
-
end
|
139
|
+
files_folder_at_customer = ""
|
125
140
|
end
|
141
|
+
|
142
|
+
if files_folder_at_customer.empty?
|
143
|
+
path_for_project = @path
|
144
|
+
else
|
145
|
+
path_for_project = ::File.expand_path(@path.downcase.sub(files_folder_at_customer.downcase, root_folder))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
return path_for_project
|
150
|
+
end
|
151
|
+
|
152
|
+
def add_to_zip_file(zip_file)
|
153
|
+
if has_relative_path?
|
154
|
+
@location_in_zip_file = "files/#{@path}"
|
155
|
+
else
|
156
|
+
@location_in_zip_file = "files/__abs/#{SecureRandom.uuid}/#{::File.basename(@path).to_s}"
|
126
157
|
end
|
127
158
|
|
159
|
+
zip_file.add(@location_in_zip_file, path_for_project)
|
160
|
+
end
|
161
|
+
|
162
|
+
def validate
|
163
|
+
error = String.new
|
164
|
+
|
128
165
|
if @name.nil? || @name.empty?
|
129
166
|
error = "#{error}A file must have a name.\n"
|
130
167
|
end
|
131
168
|
|
169
|
+
if @path.nil? || @path.empty?
|
170
|
+
error = "Path is required for file.\n"
|
171
|
+
else
|
172
|
+
if !::File.exists?(path_for_project())
|
173
|
+
error = "#{error}Can't find file with name '#{@name}' and original path '#{@path}' at '#{path_for_project()}'."
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
132
177
|
if @created_by_reference.nil?
|
133
|
-
error = "#{error}Created_by is required for file.\n"
|
178
|
+
error = "#{error}Created_by is required for file (#{@name}).\n"
|
134
179
|
end
|
135
180
|
|
136
181
|
if @organization_reference.nil? && @deal_reference.nil?
|
137
|
-
error = "#{error}
|
182
|
+
error = "#{error}The file (#{@name}) must have either an organization or a deal.\n"
|
138
183
|
end
|
139
184
|
|
140
185
|
if !@organization_reference.nil? && !@deal_reference.nil?
|
141
|
-
error = "#{error}
|
186
|
+
error = "#{error}The file (#{@name}) can't be attached to both an organization and a deal."
|
142
187
|
end
|
143
188
|
|
144
189
|
return error
|
@@ -399,18 +399,7 @@ module GoImport
|
|
399
399
|
# we dont need to check that the file exists since
|
400
400
|
# we assume that rootmodel.validate has been
|
401
401
|
# called before save_to_zip.
|
402
|
-
|
403
|
-
file.location_in_zip_file = "files/#{file.path}"
|
404
|
-
zip_file.add(file.location_in_zip_file, "#{root_folder}/#{file.path}")
|
405
|
-
else
|
406
|
-
file.location_in_zip_file = "files/__abs/#{SecureRandom.uuid}/#{::File.basename(file.path).to_s}"
|
407
|
-
if files_folder_at_customer.empty?
|
408
|
-
zip_file.add(file.location_in_zip_file, file.path)
|
409
|
-
else
|
410
|
-
zip_file.add(file.location_in_zip_file,
|
411
|
-
file.path.downcase.sub(files_folder_at_customer.downcase, root_folder))
|
412
|
-
end
|
413
|
-
end
|
402
|
+
file.add_to_zip_file(zip_file)
|
414
403
|
end
|
415
404
|
|
416
405
|
# 2) go.xml - with all data from source
|
@@ -190,6 +190,8 @@ def from_project_document_to_organization_document(row, includes, rootmodel)
|
|
190
190
|
|
191
191
|
organization_id = includes[row['idProject']]
|
192
192
|
file.organization = rootmodel.find_organization_by_integration_id(organization_id)
|
193
|
+
|
194
|
+
return file
|
193
195
|
end
|
194
196
|
|
195
197
|
def init_deal(row, rootmodel, includes)
|
data/spec/file_spec.rb
CHANGED
@@ -27,6 +27,18 @@ describe "File" do
|
|
27
27
|
file.validate.should eq ""
|
28
28
|
end
|
29
29
|
|
30
|
+
# it "fe" do
|
31
|
+
# # given
|
32
|
+
# FILES_FOLDER = "./files"
|
33
|
+
# FILES_FOLDER_AT_CUSTOMER = ""
|
34
|
+
# file.name = "Offert"
|
35
|
+
# file.path = "spec/sample_data/offert.docx"
|
36
|
+
|
37
|
+
# # when, then
|
38
|
+
|
39
|
+
# end
|
40
|
+
|
41
|
+
|
30
42
|
it "is not valid when it has path and deal" do
|
31
43
|
# must have a created_by
|
32
44
|
# given
|
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.
|
4
|
+
version: 3.0.10
|
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-10-
|
15
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: iso_country_codes
|