leap_salesforce 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.leap_salesforce.yml +4 -0
- data/ChangeLog +3 -0
- data/README.md +15 -0
- data/Rakefile +2 -0
- data/exe/leap_salesforce +13 -0
- data/leap_salesforce.gemspec +2 -1
- data/lib/leap_salesforce/ext/string.rb +6 -0
- data/lib/leap_salesforce/generator/soql_objects.rb +18 -6
- data/lib/leap_salesforce/generator/templates/soql_object_field_names.Java.erb +22 -0
- data/lib/leap_salesforce/parameters.rb +9 -0
- data/lib/leap_salesforce/version.rb +1 -1
- data/lib/leap_salesforce.rb +2 -0
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13951c22ceafff2467ca471cb6fda3c9b7ab34dd707c7e23371be362aee3199d
|
4
|
+
data.tar.gz: 2285ff9c9b90f44da101c8b186646ae8e7d4a7ff83b16bcd04807f72f5432d3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6377865707517db0bc51c59bf8e2f7d17a7ceba3191c5cd9759dfbde7e904cd2471e4574c8e981a3a781dfa1f9bc487a0f414d3b8c94c6cd618d6b2145d0b752
|
7
|
+
data.tar.gz: a033b46017e9dbd28b743a38b97fcd5c16663a5f3addf07dd3039354101a6a610c501c4f004e6ba1357d465d0a5212fb48dac1de8e20787a1565ac612148c21a
|
data/.gitignore
CHANGED
data/.leap_salesforce.yml
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
environment: prod # This is irrelevant for sfdx auth which uses user/alias
|
2
2
|
lib_folder: spec/support
|
3
3
|
sfdx: false
|
4
|
+
# Example of settings for generating Java classes
|
5
|
+
# language: java
|
6
|
+
# soql_field_start_text: |
|
7
|
+
# package com.salesforce.test.pojo.soqlObjects;
|
4
8
|
soql_objects:
|
5
9
|
- Case
|
6
10
|
- Contact
|
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -104,6 +104,8 @@ Credentials are not stored in stored in source control. They can be setting thro
|
|
104
104
|
* 'client_secret'
|
105
105
|
* 'password'
|
106
106
|
|
107
|
+
> If these variables can be set in a `.env` file they will be loaded automatically
|
108
|
+
|
107
109
|
> Security tokens can be set for each user (adding to password in OAuth like in [this article](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm))
|
108
110
|
> To do that set an environment variable as USER_KEY_token. E.g, so for a user with a key of :admin
|
109
111
|
> the token would be set with the `admin_token` environment variable
|
@@ -174,6 +176,19 @@ custom object.
|
|
174
176
|
A separate file with the ending `_field_names` is also created from the metadata for each object. This creates
|
175
177
|
accessors for each field in the table with names that map from a Ruby friendly name to the Salesforce backend name.
|
176
178
|
|
179
|
+
A java class can be created using the following syntax in `.leap_salesforce.yml`. The default language will be Ruby
|
180
|
+
|
181
|
+
```yaml
|
182
|
+
language: java
|
183
|
+
lib_folder: main/java # Path to store auto generated Java classes
|
184
|
+
soql_field_start_text: |
|
185
|
+
package com.salesforce.test.pojo.soqlObjects;
|
186
|
+
```
|
187
|
+
|
188
|
+
These task can also be executed from the executable of this project with `leap_salesforce create_soql_objects --language=ruby`
|
189
|
+
|
190
|
+
For generation of other languages, raise an issue
|
191
|
+
|
177
192
|
* `leaps:create_enums`
|
178
193
|
|
179
194
|
This task reads the soql objects defined in `.leap_salesforce.yml` and creates a `metadata/enum` folder that has
|
data/Rakefile
CHANGED
data/exe/leap_salesforce
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
5
|
|
6
6
|
require 'thor'
|
7
|
+
require 'dotenv'
|
8
|
+
Dotenv.load
|
7
9
|
require 'leap_salesforce/parameters'
|
8
10
|
require 'leap_salesforce/generator/generator'
|
9
11
|
require 'leap_salesforce/error'
|
@@ -58,6 +60,17 @@ module LeapSalesforce
|
|
58
60
|
puts 'Your .gitignore is already present so not updated.
|
59
61
|
Please ignore "config/credentials/" and "logs/"'.colorize :red
|
60
62
|
end
|
63
|
+
|
64
|
+
desc 'create_soql_objects', 'Creates SOQL objects from metadata based on .leap_salesforce.yml'
|
65
|
+
option :language, default: 'ruby'
|
66
|
+
def create_soql_objects
|
67
|
+
LeapSalesforce.language = options[:language]
|
68
|
+
require 'leap_salesforce/generator/soql_objects'
|
69
|
+
LeapSalesforce.oauth_working?
|
70
|
+
LeapSalesforce::Users.execute_as_if_present key: :admin do
|
71
|
+
LeapSalesforce::Generator::SoqlObjects.new.create_all
|
72
|
+
end
|
73
|
+
end
|
61
74
|
end
|
62
75
|
end
|
63
76
|
|
data/leap_salesforce.gemspec
CHANGED
@@ -26,7 +26,7 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
|
-
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'bundler'
|
30
30
|
spec.add_development_dependency 'parallel'
|
31
31
|
spec.add_development_dependency 'pry'
|
32
32
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
@@ -35,6 +35,7 @@ It reads the Metadata from Salesforce and creates the foundation for API tests.'
|
|
35
35
|
spec.add_development_dependency 'yard-doctest'
|
36
36
|
spec.add_dependency 'activerecord', '7'
|
37
37
|
spec.add_dependency 'colorize'
|
38
|
+
spec.add_dependency 'dotenv'
|
38
39
|
spec.add_dependency 'facets'
|
39
40
|
spec.add_dependency 'factory_bot'
|
40
41
|
spec.add_dependency 'faker', '>= 2.0'
|
@@ -92,6 +92,12 @@ class String
|
|
92
92
|
name.keyword? ? "my_#{name}" : name
|
93
93
|
end
|
94
94
|
|
95
|
+
# @return [String] Camel case string that is not taken by keywords like 'class', 'alias'
|
96
|
+
# @param [Symbol] type :upper or :lower, default :upper
|
97
|
+
def unused_camel_name(type = :upper)
|
98
|
+
unused_ruby_name.camelize(type)
|
99
|
+
end
|
100
|
+
|
95
101
|
# @return [String] Zulu time stamp for string
|
96
102
|
def to_zulu_date_string
|
97
103
|
Time.parse(self).strftime('%Y-%m-%dT%H:%M:%S.000Z')
|
@@ -12,7 +12,8 @@ module LeapSalesforce
|
|
12
12
|
class SoqlObjects
|
13
13
|
include Generator
|
14
14
|
|
15
|
-
|
15
|
+
SOQL_DATA_FOLDER = LeapSalesforce.language == "java" ? 'SoqlObjects' : 'soql_data'
|
16
|
+
SOQL_OBJECT_FOLDER = File.join(LeapSalesforce.lib_folder, SOQL_DATA_FOLDER).freeze
|
16
17
|
FACTORY_FOLDER = File.join(LeapSalesforce.lib_folder, 'factories').freeze
|
17
18
|
|
18
19
|
# Create temporary class for building API requests on
|
@@ -31,6 +32,7 @@ module LeapSalesforce
|
|
31
32
|
raise LeapSalesforce::SetupError, "Error producing Soql data for '#{@soql_class}', soql table " \
|
32
33
|
" '#{@soql_object.backend_name}'. Error message: '#{desc.error_message}'"
|
33
34
|
end
|
35
|
+
return unless LeapSalesforce.language == "ruby"
|
34
36
|
content = read_template 'soql_object.rb.erb', binding
|
35
37
|
file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.reference}.rb")
|
36
38
|
generate_file file, content, overwrite: false
|
@@ -38,13 +40,21 @@ module LeapSalesforce
|
|
38
40
|
|
39
41
|
# Generate module with fields for Soql Object
|
40
42
|
def generate_field_module
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
if LeapSalesforce.language == "ruby"
|
44
|
+
field_content = read_template 'soql_object_field_names.rb.erb', binding
|
45
|
+
field_file = File.join(SOQL_OBJECT_FOLDER, "#{@field_name_file}.rb")
|
46
|
+
elsif LeapSalesforce.language == "java"
|
47
|
+
field_content = read_template 'soql_object_field_names.Java.erb', binding
|
48
|
+
field_file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.class_name}.Java")
|
49
|
+
else
|
50
|
+
raise LeapSalesforce::SetupError, "Unsupported language '#{LeapSalesforce.language}'"
|
51
|
+
end
|
52
|
+
generate_file field_file, field_content
|
44
53
|
end
|
45
54
|
|
46
55
|
# Generate factory for mass generating objects using FactoryBot
|
47
56
|
def generate_factory
|
57
|
+
return unless LeapSalesforce.language == "ruby"
|
48
58
|
@default_fields, @other_fields = filter_fields
|
49
59
|
content = read_template 'factory.rb.erb', binding
|
50
60
|
file = File.join(FACTORY_FOLDER, "#{@soql_object.reference}.rb")
|
@@ -62,8 +72,10 @@ module LeapSalesforce
|
|
62
72
|
generate_field_module
|
63
73
|
generate_factory
|
64
74
|
end
|
65
|
-
|
66
|
-
|
75
|
+
if LeapSalesforce.language == 'ruby'
|
76
|
+
`rubocop -A #{SOQL_OBJECT_FOLDER} --enable-pending-cops`
|
77
|
+
`rubocop -A #{FACTORY_FOLDER} --enable-pending-cops`
|
78
|
+
end
|
67
79
|
end
|
68
80
|
|
69
81
|
private
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<%= LeapSalesforce.soql_field_start_text %>
|
2
|
+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
3
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Auto-generated code created by leap_salesforce. Do not manually
|
7
|
+
* update as this can be overwritten when `leap_salesforce create_soql_objects` is run
|
8
|
+
*/
|
9
|
+
@JsonIgnoreProperties(ignoreUnknown=true)
|
10
|
+
public class <%= @soql_object.class_name %> {
|
11
|
+
|
12
|
+
<% @soql_class.fields.each do |field| %>
|
13
|
+
@JsonProperty(value="<%= field['name'] %>")
|
14
|
+
String <%= field['name'].camelize(:lower) %>;
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<% @soql_class.fields.each do |field| %>
|
18
|
+
public String get<%= field['label'].unused_camel_name %>() { return <%= field['name'].camelize(:lower) %>; }
|
19
|
+
public void set<%= field['label'].unused_camel_name %>(String <%= field['name'].camelize(:lower) %>) { this.<%= field['name'].camelize(:lower) %> = <%= field['name'].camelize(:lower) %>; }
|
20
|
+
<% end %>
|
21
|
+
}
|
22
|
+
|
@@ -16,6 +16,8 @@ module LeapSalesforce
|
|
16
16
|
@client_id = ENV['client_id']
|
17
17
|
@client_secret = ENV['client_secret']
|
18
18
|
@password = ENV['password']
|
19
|
+
@language = "ruby"
|
20
|
+
@soql_field_start_text = ""
|
19
21
|
@environment = nil
|
20
22
|
@logger = Logger.new $stdout
|
21
23
|
@sfdx = false
|
@@ -130,6 +132,13 @@ module LeapSalesforce
|
|
130
132
|
# @return [Logger] Logger used by LeapSalesforce
|
131
133
|
attr_accessor :logger
|
132
134
|
|
135
|
+
# @return [Symbol] Name of the language used
|
136
|
+
attr_accessor :language
|
137
|
+
|
138
|
+
# @return [String] Text to be added as start of auto generated Soql field names
|
139
|
+
# classes in the Salesforce object
|
140
|
+
attr_accessor :soql_field_start_text
|
141
|
+
|
133
142
|
# @return [Array] list_of_soql_objects Array describing Soql objects taken from .leap_salesforce.yml
|
134
143
|
def soql_objects=(list_of_soql_objects)
|
135
144
|
@soql_objects = list_of_soql_objects.collect do |soql_object_desc|
|
data/lib/leap_salesforce.rb
CHANGED
@@ -21,6 +21,8 @@ require 'faker' # For fake data
|
|
21
21
|
require 'leap_salesforce/error'
|
22
22
|
require 'leap_salesforce/loader'
|
23
23
|
require 'leap_salesforce/session'
|
24
|
+
require 'dotenv'
|
25
|
+
Dotenv.load
|
24
26
|
|
25
27
|
# If variable is present within LeapSalesforce set it
|
26
28
|
def load_variables_from(file)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leap_salesforce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IQA
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - "
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: parallel
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +137,20 @@ dependencies:
|
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: dotenv
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
140
154
|
- !ruby/object:Gem::Dependency
|
141
155
|
name: facets
|
142
156
|
requirement: !ruby/object:Gem::Requirement
|
@@ -346,6 +360,7 @@ files:
|
|
346
360
|
- lib/leap_salesforce/generator/templates/factory.rb.erb
|
347
361
|
- lib/leap_salesforce/generator/templates/picklist.rb.erb
|
348
362
|
- lib/leap_salesforce/generator/templates/soql_object.rb.erb
|
363
|
+
- lib/leap_salesforce/generator/templates/soql_object_field_names.Java.erb
|
349
364
|
- lib/leap_salesforce/generator/templates/soql_object_field_names.rb.erb
|
350
365
|
- lib/leap_salesforce/generator/templates/spec/crud_eg_spec.rb.erb
|
351
366
|
- lib/leap_salesforce/generator/templates/spec/limit_spec.rb.erb
|