Class: UseSalesforceDataLoader
- Inherits:
-
Object
- Object
- UseSalesforceDataLoader
- Defined in:
- lib/use_salesforce_dataloader.rb
Overview
Standard file layout (allow different layout):
-
conf_dir/-
key.txt -
process-conf.xml -
map.sdl
-
Constant Summary collapse
- VERSION =
'0.0.8'- PROCESS_XML_TEMPLATE =
Note:
internal use
"<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\" \"http://www.springframework.org/dtd/spring-beans.dtd\">\n<beans>\n <bean id=\"%s\"\n class=\"com.salesforce.dataloader.process.ProcessRunner\"\n singleton=\"false\">\n <description>%s</description>\n <property name=\"name\" value=\"%s\"/>\n <property name=\"configOverrideMap\">\n <map>\n%s\n </map>\n </property>\n </bean>\n</beans>\n"- ENTRIES_XML_TEMPLATE =
Note:
internal use
" <entry key=\"%s\" value=\"%s\"/>\n"- BASE_ENTRIES =
Note:
internal use
{ 'dataAccess.readUTF8' => 'true', 'dataAccess.writeUTF8' => 'true', 'dataAccess.name' => nil, 'dataAccess.readBatchSize' => nil, 'dataAccess.type' => nil, 'dataAccess.writeBatchSize' => nil, 'process.enableExtractStatusOutput' => 'false', 'process.enableLastRunOutput' => 'true', 'process.encryptionKeyFile' => nil, # see also #conf_dir 'process.initialLastRunDate' => nil, 'process.lastRunOutputDirectory' => nil, # see also #conf_dir 'process.loadRowToStartAt' => nil, 'process.mappingFile' => nil, # see also #conf_dir 'process.operation' => nil, 'process.statusOutputDirectory' => nil, # see also #conf_dir 'process.outputError' => nil, 'process.outputSuccess' => nil, 'process.useEuropeanDates' => nil, 'sfdc.assignmentRule' => nil, 'sfdc.bulkApiCheckStatusInterval' => nil, 'sfdc.bulkApiSerialMode' => 'false', 'sfdc.bulkApiZipContent' => nil, 'sfdc.connectionTimeoutSecs' => nil, 'sfdc.debugMessages' => nil, 'sfdc.debugMessagesFile' => nil, 'sfdc.enableRetries' => nil, 'sfdc.endpoint' => nil, # see also #endpoint 'sfdc.entity' => nil, 'sfdc.externalIdField' => nil, 'sfdc.extractionRequestSize' => nil, 'sfdc.extractionSOQL' => nil, 'sfdc.insertNulls' => 'true', 'sfdc.loadBatchSize' => nil, # recommended value? -> 200(Not Bulk API) / 2000(Bulk API) 'sfdc.maxRetries' => nil, 'sfdc.minRetrySleepSecs' => nil, 'sfdc.noCompression' => nil, 'sfdc.password' => nil, # see also #password 'sfdc.proxyHost' => nil, 'sfdc.proxyPassword' => nil, 'sfdc.proxyPort' => nil, 'sfdc.proxyUsername' => nil, 'sfdc.resetUrlOnLogin' => nil, 'sfdc.timeoutSecs' => nil, 'sfdc.timezone' => nil, 'sfdc.truncateFields' => 'false', 'sfdc.useBulkApi' => nil, 'sfdc.username' => nil, # see also #username }
Instance Attribute Summary collapse
- #bean_description ⇒ String
- #bean_id ⇒ String
-
#conf_key_file ⇒ String
Path of conf_key_file.
-
#conf_map_file ⇒ String
Path of conf_map_file.
-
#conf_process_xml_file ⇒ String
Path of conf_process_xml_file.
-
#endpoint ⇒ String
Set/get
sfdc.endpointin XML config. - #overwrite_entries ⇒ String
-
#password ⇒ String
Set/get
sfdc.passwordin XML config. - #property_name ⇒ String
-
#username ⇒ String
Set/get
sfdc.usernamein XML config.
Instance Method Summary collapse
-
#conf_dir ⇒ String
Path of conf_dir.
-
#conf_dir=(path) ⇒ Object
Setter for
@conf_dir, set values@conf_key_file,@conf_process_xml_fileand@conf_map_fileat the same time. -
#conf_process_xml ⇒ String
Generate XML config.
-
#default_overwrite_entries ⇒ Hash
internal use.
-
#encrypt(options) ⇒ String
internal use.
-
#initialize(jar, java = nil, java_opt = nil) ⇒ UseSalesforceDataLoader
constructor
A new instance of UseSalesforceDataLoader.
-
#process_cmd(name) ⇒ String
Return command line string for execute dataloader by named process.
-
#save_conf_key_file ⇒ String
Save encrypt key file.
-
#save_conf_process_xml_file ⇒ String
Save conf xml file.
Constructor Details
#initialize(jar, java = nil, java_opt = nil) ⇒ UseSalesforceDataLoader
Returns a new instance of UseSalesforceDataLoader.
81 82 83 84 85 86 87 88 |
# File 'lib/use_salesforce_dataloader.rb', line 81 def initialize(jar, java = nil, java_opt = nil) java = exec_command('which java') unless java path_check(java) path_check(jar) j = [java, java_opt, '-cp', jar].compact.join(' ') @encrypt = "#{j} com.salesforce.dataloader.security.EncryptionUtil" @process = "#{j} -Dsalesforce.config.dir=%s com.salesforce.dataloader.process.ProcessRunner process.name=%s" end |
Instance Attribute Details
#bean_description ⇒ String
65 66 67 |
# File 'lib/use_salesforce_dataloader.rb', line 65 def bean_description @bean_description end |
#bean_id ⇒ String
61 62 63 |
# File 'lib/use_salesforce_dataloader.rb', line 61 def bean_id @bean_id end |
#conf_key_file ⇒ String
Returns path of conf_key_file.
31 32 33 |
# File 'lib/use_salesforce_dataloader.rb', line 31 def conf_key_file @conf_key_file end |
#conf_map_file ⇒ String
Returns path of conf_map_file.
39 40 41 |
# File 'lib/use_salesforce_dataloader.rb', line 39 def conf_map_file @conf_map_file end |
#conf_process_xml_file ⇒ String
Returns path of conf_process_xml_file.
35 36 37 |
# File 'lib/use_salesforce_dataloader.rb', line 35 def conf_process_xml_file @conf_process_xml_file end |
#endpoint ⇒ String
Set/get sfdc.endpoint in XML config.
45 46 47 |
# File 'lib/use_salesforce_dataloader.rb', line 45 def endpoint @endpoint end |
#overwrite_entries ⇒ String
73 74 75 |
# File 'lib/use_salesforce_dataloader.rb', line 73 def overwrite_entries @overwrite_entries end |
#password ⇒ String
Set/get sfdc.password in XML config.
57 58 59 |
# File 'lib/use_salesforce_dataloader.rb', line 57 def password @password end |
#property_name ⇒ String
69 70 71 |
# File 'lib/use_salesforce_dataloader.rb', line 69 def property_name @property_name end |
#username ⇒ String
Set/get sfdc.username in XML config.
51 52 53 |
# File 'lib/use_salesforce_dataloader.rb', line 51 def username @username end |
Instance Method Details
#conf_dir ⇒ String
Returns path of conf_dir.
25 26 27 |
# File 'lib/use_salesforce_dataloader.rb', line 25 def conf_dir @conf_dir end |
#conf_dir=(path) ⇒ Object
Setter for @conf_dir, set values @conf_key_file, @conf_process_xml_file and @conf_map_file at the same time.
15 16 17 18 19 20 21 |
# File 'lib/use_salesforce_dataloader.rb', line 15 def conf_dir=(path) @conf_dir = path @conf_key_file = @conf_dir + '/key.txt' @conf_map_file = @conf_dir + '/map.sdl' @conf_process_xml_file = @conf_dir + '/process-conf.xml' @conf_dir end |
#conf_process_xml ⇒ String
Generate XML config
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/use_salesforce_dataloader.rb', line 131 def conf_process_xml entries = BASE_ENTRIES.merge(default_overwrite_entries) entries.merge!(@overwrite_entries) if @overwrite_entries entries_xml = entries .select{|k, v| v} .map{|k, v| ENTRIES_XML_TEMPLATE % [k, v]} .join .chomp PROCESS_XML_TEMPLATE % [@bean_id, @bean_descrption, @property_name, entries_xml] end |
#default_overwrite_entries ⇒ Hash
internal use
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/use_salesforce_dataloader.rb', line 174 def default_overwrite_entries path_check(@conf_key_file) encrypt_password = encrypt("-e '#{@password}' '#{@conf_key_file}'") { 'sfdc.endpoint' => @endpoint, 'sfdc.username' => @username, 'sfdc.password' => encrypt_password, 'process.encryptionKeyFile' => @conf_key_file, 'process.lastRunOutputDirectory' => @conf_dir, 'process.statusOutputDirectory' => @conf_dir, 'process.mappingFile' => @conf_map_file, } end |
#encrypt(options) ⇒ String
Original:
dataloader/bin/encrypt.sh
Usage: dataloader/bin/encrypt.sh
Utility to encrypt a string based on a static or a provided key
Options (mutually exclusive - use one at a time):
-g <seed text> Generate key based on seed
-v <encrypted> <decrypted value> [Path to Key] Validate whether decryption of encrypted value matches the decrypted value, optionally provide key file
-e <plain text> [Path to Key] Encrypt a plain text value, optionally provide key file (generate key using option -g)
internal use
166 167 168 169 |
# File 'lib/use_salesforce_dataloader.rb', line 166 def encrypt() cmd = "#{@encrypt} #{options} | sed 's/^.*) \- //g'" exec_command(cmd) end |
#process_cmd(name) ⇒ String
Original:
dataloader/bin/process.sh
Usage: dataloader/bin/process.sh [conf-dir] <process-name>
Return command line string for execute dataloader by named process.
101 102 103 104 105 |
# File 'lib/use_salesforce_dataloader.rb', line 101 def process_cmd(name) path_check(@conf_dir) path_check(@conf_process_xml_file) @process % [@conf_dir, name] end |
#save_conf_key_file ⇒ String
Save encrypt key file
110 111 112 113 114 115 116 |
# File 'lib/use_salesforce_dataloader.rb', line 110 def save_conf_key_file @conf_key_file.tap do |f| open(f, 'w:UTF-8') do |o| o.print encrypt("-g #{text_seed}") end end end |
#save_conf_process_xml_file ⇒ String
Save conf xml file
121 122 123 124 125 126 127 |
# File 'lib/use_salesforce_dataloader.rb', line 121 def save_conf_process_xml_file @conf_process_xml_file.tap do |f| open(f, 'w:UTF-8') do |o| o.print conf_process_xml end end end |