go_import 3.0.0

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.
Files changed (90) hide show
  1. data/bin/go-import +96 -0
  2. data/lib/go_import/csv_helper.rb +47 -0
  3. data/lib/go_import/email_helper.rb +10 -0
  4. data/lib/go_import/errors.rb +22 -0
  5. data/lib/go_import/excel_helper.rb +10 -0
  6. data/lib/go_import/global_phone.json +6571 -0
  7. data/lib/go_import/model/address.rb +61 -0
  8. data/lib/go_import/model/class_settings.rb +50 -0
  9. data/lib/go_import/model/coworker.rb +76 -0
  10. data/lib/go_import/model/coworker_reference.rb +33 -0
  11. data/lib/go_import/model/customfield.rb +87 -0
  12. data/lib/go_import/model/deal.rb +172 -0
  13. data/lib/go_import/model/deal_class_settings.rb +73 -0
  14. data/lib/go_import/model/deal_state.rb +15 -0
  15. data/lib/go_import/model/deal_status.rb +23 -0
  16. data/lib/go_import/model/deal_status_reference.rb +47 -0
  17. data/lib/go_import/model/deal_status_setting.rb +49 -0
  18. data/lib/go_import/model/documents.rb +51 -0
  19. data/lib/go_import/model/link.rb +70 -0
  20. data/lib/go_import/model/note.rb +97 -0
  21. data/lib/go_import/model/note_classification.rb +25 -0
  22. data/lib/go_import/model/organization.rb +219 -0
  23. data/lib/go_import/model/person.rb +151 -0
  24. data/lib/go_import/model/referencetosource.rb +46 -0
  25. data/lib/go_import/model/relation.rb +23 -0
  26. data/lib/go_import/model/rootmodel.rb +359 -0
  27. data/lib/go_import/model/settings.rb +61 -0
  28. data/lib/go_import/model/tag.rb +35 -0
  29. data/lib/go_import/model_helpers.rb +54 -0
  30. data/lib/go_import/phone_helper.rb +74 -0
  31. data/lib/go_import/roo_helper.rb +80 -0
  32. data/lib/go_import/serialize_helper.rb +186 -0
  33. data/lib/go_import/source.rb +87 -0
  34. data/lib/go_import/templating.rb +52 -0
  35. data/lib/go_import.rb +19 -0
  36. data/sources/csv/.gitignore +14 -0
  37. data/sources/csv/.go_import/runner.rb +62 -0
  38. data/sources/csv/Gemfile +5 -0
  39. data/sources/csv/Rakefile.rb +7 -0
  40. data/sources/csv/converter.rb +179 -0
  41. data/sources/csv/data/coworkers.csv +2 -0
  42. data/sources/csv/data/deals.csv +2 -0
  43. data/sources/csv/data/organizations.csv +2 -0
  44. data/sources/csv/data/persons.csv +2 -0
  45. data/sources/csv/spec/exporter_spec.rb +17 -0
  46. data/sources/csv/spec/sample_data/coworkers.csv +2 -0
  47. data/sources/csv/spec/sample_data/deals.csv +2 -0
  48. data/sources/csv/spec/sample_data/organizations.csv +2 -0
  49. data/sources/csv/spec/sample_data/persons.csv +2 -0
  50. data/sources/csv/spec/spec_helper.rb +30 -0
  51. data/sources/easy/.gitignore +14 -0
  52. data/sources/easy/.go_import/runner.rb +115 -0
  53. data/sources/easy/Export/readme.txt +6 -0
  54. data/sources/easy/Gemfile +5 -0
  55. data/sources/easy/Rakefile.rb +7 -0
  56. data/sources/easy/converter.rb +435 -0
  57. data/sources/easy/spec/exporter_spec.rb +10 -0
  58. data/sources/easy/spec/sample_data/Company.txt +649 -0
  59. data/sources/easy/spec/spec_helper.rb +30 -0
  60. data/sources/excel/.gitignore +14 -0
  61. data/sources/excel/.go_import/runner.rb +116 -0
  62. data/sources/excel/Gemfile +6 -0
  63. data/sources/excel/Rakefile.rb +7 -0
  64. data/sources/excel/converter.rb +130 -0
  65. data/sources/excel/spec/sample_data/sample.xlsx +0 -0
  66. data/sources/excel/spec/spec_helper.rb +26 -0
  67. data/sources/excel/spec/tomodel_spec.rb +18 -0
  68. data/sources/excel/template.xlsx +0 -0
  69. data/spec/address_spec.rb +49 -0
  70. data/spec/class_settings_spec.rb +37 -0
  71. data/spec/coworker_spec.rb +94 -0
  72. data/spec/custom_field_spec.rb +22 -0
  73. data/spec/deal_class_settings_spec.rb +104 -0
  74. data/spec/deal_spec.rb +182 -0
  75. data/spec/deal_status_reference_spec.rb +17 -0
  76. data/spec/documents_spec.rb +37 -0
  77. data/spec/helpers/csv_helper_spec.rb +29 -0
  78. data/spec/helpers/email_helper_spec.rb +32 -0
  79. data/spec/helpers/phone_helper_spec.rb +97 -0
  80. data/spec/helpers/roo_helper_spec.rb +10 -0
  81. data/spec/helpers/serialize_helper_spec.rb +249 -0
  82. data/spec/helpers/xsd_validate_spec.rb +55 -0
  83. data/spec/link_spec.rb +106 -0
  84. data/spec/note_spec.rb +110 -0
  85. data/spec/organization_spec.rb +151 -0
  86. data/spec/person_spec.rb +132 -0
  87. data/spec/rootmodel_spec.rb +371 -0
  88. data/spec/spec_helper.rb +30 -0
  89. data/spec/templating_spec.rb +12 -0
  90. metadata +306 -0
data/bin/go-import ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "go_import"
5
+
6
+ class GoImportCommandLine < Thor
7
+
8
+ desc "about", "About go-import"
9
+ def about()
10
+ puts "go-import is an import tool for LIME Go. It can take virtually any input source and create pretty looking xml-files that LIME Go likes. go-import has some predefined sources that will make it easy for you to migrate your data."
11
+ puts ""
12
+ end
13
+
14
+ desc "list-sources", "Lists the available sources"
15
+ def list_sources()
16
+ puts "The following sources are available:"
17
+ puts
18
+
19
+ sources = GoImport::Sources.new(source_path)
20
+ sources.list().each do |s|
21
+ puts "\t#{s}"
22
+ end
23
+
24
+ puts "\nCreate a new project with 'go-import new' with one of these sources."
25
+ end
26
+
27
+ desc "new", "Creates a new migration project with a specifed name and source"
28
+ option(:project,
29
+ :desc => "Name of the project. The project will be created in a folder with the same name.",
30
+ :type => :string,
31
+ :required => true)
32
+ option(:source,
33
+ :desc => "Name of the source to use. Use list-sources to show available sources.",
34
+ :type => :string,
35
+ :required => true)
36
+ def new(project = nil, source = nil)
37
+ sources = GoImport::Sources.new(source_path)
38
+
39
+ if sources.create_project_from_source(options.project, options.source)
40
+ puts "\nProject '#{options.project}' created from source '#{options.source}'."
41
+ puts "Modify the #{options.project}/converter.rb script to suit your source."
42
+ puts "Use 'go-import run' from the project directory to create the xml file for LIME Go."
43
+ end
44
+ end
45
+
46
+ desc "run", "Executes the current project and create a go-import.xml file. Existing go-import.xml will be overwritten, use -o to specify a different filename"
47
+ def run_import()
48
+ # run is a Thor reserved word and cant be used as a method name
49
+
50
+ runner_dir = ".go_import"
51
+
52
+ if Dir.exists?(runner_dir) == false
53
+ puts "This doesnt look like a go-import project. Are you in the right directory or did you mess with the '#{runner_dir}' folder?"
54
+ return
55
+ end
56
+
57
+ runner_file = File.expand_path('./.go_import/runner.rb', Dir.pwd)
58
+ if File.exists?(runner_file) == false
59
+ puts "I can't run this project. Did you mess with the '#{runner_dir}' folder?"
60
+ return
61
+ end
62
+
63
+ require(runner_file)
64
+
65
+ # the source must implement the convert_source method that
66
+ # returns an instance of GoImport::RootModel
67
+ model = convert_source()
68
+
69
+ go_data_filename = "go.xml"
70
+
71
+ error = model.sanity_check
72
+ if error.empty?
73
+ validation_errors = model.validate
74
+
75
+ if validation_errors.empty?
76
+ model.serialize_to_file(go_data_filename)
77
+ puts "Source has been been converted into '#{go_data_filename}'."
78
+ else
79
+ puts "Source could not be converted due to"
80
+ puts validation_errors
81
+ end
82
+ else
83
+ puts "Source could not be converted due to"
84
+ puts error
85
+ end
86
+
87
+ end
88
+
89
+ private
90
+ def source_path()
91
+ File.expand_path("../sources", File.dirname(__FILE__))
92
+ end
93
+ end
94
+
95
+ GoImportCommandLine.start(ARGV)
96
+
@@ -0,0 +1,47 @@
1
+ require "csv"
2
+ module GoImport
3
+ module CsvHelper
4
+
5
+ # @example Detect column separator and transform to hashes
6
+ # hashes = GoImport::CsvHelper.text_to_hashes(text)
7
+ #
8
+ # @example Use specific column separator and transform to hashes
9
+ # column_separator = ','
10
+ # hashes = GoImport::CsvHelper.text_to_hashes(text, column_separator)
11
+ def self.text_to_hashes(text, column_separator = nil, row_separator = :auto, quote_char = '"')
12
+ if !text
13
+ raise "Missing text"
14
+ end
15
+
16
+ if !column_separator
17
+ column_separator = self.detect_col_sep text
18
+ end
19
+
20
+ rows = CSV.parse(text.strip,{:col_sep => column_separator,
21
+ :row_sep => row_separator, :quote_char => quote_char})
22
+ map = {}
23
+ first = rows.first
24
+ (0 .. first.length-1).each do |i|
25
+ map[i] = first[i]
26
+ end
27
+ rs = []
28
+ (1 .. rows.length-1).each do |i|
29
+ r={}
30
+ (0 .. map.length-1).each do |j|
31
+ r[map[j]] = rows[i][j]
32
+ end
33
+ rs.push(r)
34
+ end
35
+ return rs
36
+ end
37
+
38
+ private
39
+ def self.detect_col_sep(text)
40
+ firstline = text.split('\n').first
41
+ col_seps = [';','\t',',']
42
+ return col_seps.find do |c|
43
+ firstline.include? c
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ require "sixarm_ruby_email_address_validation"
2
+
3
+ module GoImport
4
+ # The EmailHelper helps you validate email addresses.
5
+ class EmailHelper
6
+ def self.is_valid?(email)
7
+ return (email =~ EmailAddressValidation::Pattern) ? true : false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ module GoImport
2
+ class AlreadyAddedError < StandardError
3
+ end
4
+
5
+ class InvalidCustomFieldError < StandardError
6
+ end
7
+
8
+ class InvalidRelationError < StandardError
9
+ end
10
+
11
+ class InvalidValueError < StandardError
12
+ def initalize(value)
13
+ super("#{value} is not a valid value.")
14
+ end
15
+ end
16
+
17
+ class InvalidDealStatusError < StandardError
18
+ end
19
+
20
+ class InvalidNoteClassificationError < StandardError
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ module GoImport
2
+ # The ExcelHelper just makes it a little bit easier to open an
3
+ # excel file in the imports. With ExcelHelper you don't need to
4
+ # know anything about Roo and RooHelper.
5
+ class ExcelHelper
6
+ def self.Open(excel_filename)
7
+ return RooHelper.new(Roo::Excelx.new(excel_filename))
8
+ end
9
+ end
10
+ end