leap_salesforce 1.3.1 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b3796e62552604c5d65b95ae7fb7e8771038772ccabb7c7251e792baa27de5a
4
- data.tar.gz: 9f0904a42010ee3844e46554f8a1dbd85883bf69afedb43b2e828c8090194b63
3
+ metadata.gz: b60fb84b150303c1dc91eb621c40d5c155f439ecd7047911a321d65129259943
4
+ data.tar.gz: '0966f9cb9274d9f5d7f3d9f2cc85391bf57b909eb6c2d63792452a70e5f690f3'
5
5
  SHA512:
6
- metadata.gz: 2dffa3ad733919a61f09d07f06b396055a4d70453988bec12817d627be9633f65a7c785f852d772b62642ad789113385ab3fe1beefbd41a3811fb7595de28f15
7
- data.tar.gz: 2eddc54342f6d2b32c26765c7072903e2481ba26265fd28aa6c33f282cd91d23a0204d160a3cfcdeeed7e429f12c3ab168eb941b987bc7b8b98bd2ba170c2542
6
+ metadata.gz: dc9ae149d641d926b3d165c28356a39655b5bc1376488db5526b4b61dffe351d7212a05b800b0e932796fcb40296f39face2cd68e67347987925d74c6eae56b6
7
+ data.tar.gz: 8a7de04ea12fa03beaf419a756f4a9bc5acdba392b9162d7e920aa29652c882034488e69ee2d569b095e0e57f9266ca8002a5b95544be7e2c716ffdfbdb094f4
data/.gitignore CHANGED
@@ -18,6 +18,7 @@ spec/support/
18
18
 
19
19
  # Here are folders related to testing this project in it's own CI
20
20
  config/credentials/
21
+ .env
21
22
 
22
23
  # rspec failure tracking
23
24
  .rspec_status
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
@@ -1,3 +1,10 @@
1
+ Version 1.4.1
2
+ * Fixed method names that need to match types
3
+ * Fixed file name created. Needs to be with '.java' in lower case
4
+
5
+ Version 1.4
6
+ * Ability to generate Java classes from metadata using the exe 'leap_salesforce create_soql_objects --language=java'
7
+
1
8
  Version 1.3.1
2
9
  * Require facets so that `snakecase` method ensured to work
3
10
 
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
@@ -7,6 +7,8 @@ require 'rake/clean'
7
7
  require 'yard'
8
8
  require 'yard/doctest/rake'
9
9
 
10
+ require 'dotenv'
11
+ Dotenv.load
10
12
  require 'leap_salesforce/rake' # TODO: Append this line to existing repo
11
13
 
12
14
  CLEAN.include 'tmp/*'
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,22 @@ 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
66
+ def create_soql_objects
67
+ LeapSalesforce.language = options[:language] if 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
74
+
75
+ desc 'version', 'Version this library'
76
+ def version
77
+ puts LeapSalesforce::VERSION
78
+ end
61
79
  end
62
80
  end
63
81
 
@@ -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', '~> 2.0'
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
- SOQL_OBJECT_FOLDER = File.join(LeapSalesforce.lib_folder, 'soql_data').freeze
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,8 @@ 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'
36
+
34
37
  content = read_template 'soql_object.rb.erb', binding
35
38
  file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.reference}.rb")
36
39
  generate_file file, content, overwrite: false
@@ -38,13 +41,22 @@ module LeapSalesforce
38
41
 
39
42
  # Generate module with fields for Soql Object
40
43
  def generate_field_module
41
- field_content = read_template 'soql_object_field_names.rb.erb', binding
42
- field_file = File.join(SOQL_OBJECT_FOLDER, "#{@field_name_file}.rb")
44
+ if LeapSalesforce.language == 'ruby'
45
+ field_content = read_template 'soql_object_field_names.rb.erb', binding
46
+ field_file = File.join(SOQL_OBJECT_FOLDER, "#{@field_name_file}.rb")
47
+ elsif LeapSalesforce.language == "java"
48
+ field_content = read_template 'soql_object_field_names.java.erb', binding
49
+ field_file = File.join(SOQL_OBJECT_FOLDER, "#{@soql_object.class_name}.java")
50
+ else
51
+ raise LeapSalesforce::SetupError, "Unsupported language '#{LeapSalesforce.language}'"
52
+ end
43
53
  generate_file field_file, field_content
44
54
  end
45
55
 
46
56
  # Generate factory for mass generating objects using FactoryBot
47
57
  def generate_factory
58
+ return unless LeapSalesforce.language == 'ruby'
59
+
48
60
  @default_fields, @other_fields = filter_fields
49
61
  content = read_template 'factory.rb.erb', binding
50
62
  file = File.join(FACTORY_FOLDER, "#{@soql_object.reference}.rb")
@@ -62,6 +74,8 @@ module LeapSalesforce
62
74
  generate_field_module
63
75
  generate_factory
64
76
  end
77
+ return unless LeapSalesforce.language == 'ruby'
78
+
65
79
  `rubocop -A #{SOQL_OBJECT_FOLDER} --enable-pending-cops`
66
80
  `rubocop -A #{FACTORY_FOLDER} --enable-pending-cops`
67
81
  end
@@ -0,0 +1,25 @@
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['name'].camelize(:upper) %>() { return <%= field['name'].camelize(:lower) %>; }
19
+ /**
20
+ * Label: '<%= field['label'] %>', Type: <%= field['type'] %><%= ", Relationship:" + field['relationshipName'] if field['relationshipName'] %>
21
+ */
22
+ public void set<%= field['name'].camelize(:upper) %>(String <%= field['name'].camelize(:lower) %>) { this.<%= field['name'].camelize(:lower) %> = <%= field['name'].camelize(:lower) %>; }
23
+ <% end %>
24
+ }
25
+
@@ -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|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'auth'
2
4
  require 'savon'
3
5
  require 'json'
@@ -21,12 +23,11 @@ module LeapSalesforce
21
23
  end
22
24
 
23
25
  class << self
24
-
25
26
  # Login via SOAP API
26
27
  def soap_login(username, password, security_token)
27
28
  client = Savon.client do
28
29
  endpoint "#{SoqlHandler.instance_url}/services/Soap/u/51.0"
29
- namespace "urn:partner.soap.sforce.com"
30
+ namespace 'urn:partner.soap.sforce.com'
30
31
  log true # See request and response. (Put this in traffic file)
31
32
  log_level :debug
32
33
  logger Soaspec::SpecLogger.create
@@ -120,7 +120,7 @@ module LeapSalesforce
120
120
  value = value.nil? ? 'null' : value.to_s
121
121
  operator, value = case value[0]
122
122
  when '>', '<', '!', 'I' then extract_comparator(value)
123
- when '~' then ['LIKE', value[1..-1]]
123
+ when '~' then ['LIKE', value[1..]]
124
124
  else ['=', value]
125
125
  end
126
126
  case soql_table.type_for(field_name)
@@ -142,18 +142,18 @@ module LeapSalesforce
142
142
  # @return [Array] Extract of operator, value, taking >, >, >= from string and rest of string
143
143
  def extract_comparator(value)
144
144
  if value[1] == '='
145
- [value[0..1], value[2..-1]]
145
+ [value[0..1], value[2..]]
146
146
  elsif value[0..2] == '!IN'
147
- ['NOT IN', value[3..-1].to_soql_array]
147
+ ['NOT IN', value[3..].to_soql_array]
148
148
  elsif value[0..1] == 'IN'
149
- ['IN', value[2..-1].to_soql_array]
149
+ ['IN', value[2..].to_soql_array]
150
150
  elsif value[0] == 'I' # 'N' not 2nd character
151
151
  ['=', value]
152
152
  elsif value[0] == '!'
153
- remaining = value[1..-1] == 'nil' ? 'null' : value[1..-1]
153
+ remaining = value[1..] == 'nil' ? 'null' : value[1..]
154
154
  ['!=', remaining]
155
155
  else
156
- [value[0], value[1..-1]]
156
+ [value[0], value[1..]]
157
157
  end
158
158
  end
159
159
  end
@@ -49,7 +49,7 @@ class SoqlData < Exchange
49
49
  if @override_parameters && @override_parameters[:suburl]
50
50
  suburl_passed = @override_parameters[:suburl]
51
51
  @override_parameters[:suburl] = if suburl_passed.include?('sobjects')
52
- suburl_passed[suburl_passed.index('sobjects')..-1]
52
+ suburl_passed[suburl_passed.index('sobjects')..]
53
53
  else
54
54
  suburl_passed
55
55
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module LeapSalesforce
4
4
  # @return [String] Version of leap salesforce
5
- VERSION = '1.3.1'
5
+ VERSION = '1.4.1'
6
6
  end
@@ -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.3.1
4
+ version: 1.4.1
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-08-04 00:00:00.000000000 Z
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: '2.0'
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: '2.0'
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