leap_salesforce 1.4.2 → 1.4.3

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: 727cda791511d2d4114ed478b5686cdcdf194d57d38b43258180f1e9edf2dda8
4
- data.tar.gz: 3ee6582c6ec6365ea2e64fb1fe8368047171414086c2278689e0bd3c7de7f274
3
+ metadata.gz: 65554ee3c2903f5a1d49f2433d6ae95f89b98acd1d31c110b61f34eba61c2660
4
+ data.tar.gz: f5bbc9c392441f97bfe3f38046f18c8e27529a8805ebdc6229f4a47a7f755b2d
5
5
  SHA512:
6
- metadata.gz: 7382790fba0ca2416cd50d4a547c46572e16ac575b9e989b27dbbf921e8074507b8627db3daf0acbdb60533c02a65aaeeac35ed4475ad64c166ac1ee263f1b86
7
- data.tar.gz: 431a449bec6a0989ec7188b2dbd2a24fbe5d806b941c5b62dad86c1db027f559d8397545d17f3765d190ffe56ccab91a7f1b1cbd31d2769ac6fddbb5a704e476
6
+ metadata.gz: 30edbcffe1599ee7b1a8ac199e357b7b8143a10d697c623faf492704f5aa8450fd6f81694dd6a4be5ce5c59fa23c20e069fee1bac1a4f1b69c76c6feb93f04c6
7
+ data.tar.gz: cfa46d6dc2f7e6a50c24fc5bfa1635985d823ea5fe20fb54dc5706d7acf6323fe6333c783b292fa9bd0ff7f7d08a19c9ae942c74bf4bbfe88201a15268ee96c2
data/.leap_salesforce.yml CHANGED
@@ -1,10 +1,11 @@
1
1
  environment: prod # This is irrelevant for sfdx auth which uses user/alias
2
2
  lib_folder: spec/support
3
+ # enum_folder: spec/support/enum
3
4
  sfdx: false
4
5
  # Example of settings for generating Java classes
5
6
  # language: java
6
- # soql_field_start_text: |
7
- # package com.salesforce.test.pojo.soqlObjects;
7
+ # soql_field_start_text: package com.salesforce.test.pojo.soqlObjects;
8
+ # soql_enum_start_text: package com.salesforce.test.enums
8
9
  soql_objects:
9
10
  - Case
10
11
  - Contact
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ Version 1.4.3
2
+ * Simplify Java POMO's created using Lombok
3
+ * Add executable to create enum objects in Java with 'leap_salesforce create_soql_enums' and 'leap_salesforce create_all' that creates both objects and enums
4
+
1
5
  Version 1.4.2
2
6
  * Fixed leap_salesforce version method
3
7
 
data/README.md CHANGED
@@ -224,6 +224,8 @@ RSpec.describe 'Picklists' do
224
224
  end
225
225
  ```
226
226
 
227
+ One can also create this using the executable, e.g `leap_salesforce create_soql_enums`.
228
+
227
229
  #### Changing environment
228
230
 
229
231
  The `LEAP_ENV` environment variable can be used to change environment in non sfdx mode. The default is set through
data/exe/leap_salesforce CHANGED
@@ -71,6 +71,25 @@ Please ignore "config/credentials/" and "logs/"'.colorize :red
71
71
  end
72
72
  end
73
73
 
74
+ desc 'create_soql_enums', 'Creates enum objects for SOQL objects from metadata based on .leap_salesforce.yml'
75
+ option :language
76
+ def create_soql_enums(check_auth = true)
77
+ LeapSalesforce.language = options[:language] if options[:language]
78
+ require 'leap_salesforce/generator/soql_enums'
79
+ LeapSalesforce::Users.execute_as_if_present key: :admin do
80
+ LeapSalesforce::Generator::SoqlEnums.new.create
81
+ end
82
+ end
83
+
84
+ desc 'create_all', 'Creates SOQL objects and enum objects from metadata based on .leap_salesforce.yml'
85
+ option :language
86
+ def create_all
87
+ puts 'Creating soql objects'.colorize :yellow
88
+ create_soql_objects
89
+ puts 'Creating soql enums'.colorize :yellow
90
+ create_soql_enums
91
+ end
92
+
74
93
  desc 'version', 'Version this library'
75
94
  def version
76
95
  puts LeapSalesforce::VERSION
@@ -1,26 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'soql_objects'
4
+ require_relative '../soql_data/soql_data'
4
5
 
5
6
  module LeapSalesforce
6
7
  # Generators for creating code
7
8
  module Generator
8
- # Creates Soql Enumerations / Picklists from objects in LeapSalesforce.objects_to_verify
9
+ # Creates Soql Enumerations / Picklists from objects in LeapSalesforce.soql_objects
9
10
  class SoqlEnums
10
11
  include Generator
11
12
 
12
13
  # @return [String] Folder where enumeration objects are stored
13
- ENUM_FOLDER = File.join(LeapSalesforce.lib_folder, 'metadata', 'enum').freeze
14
+ if LeapSalesforce.enum_folder
15
+ ENUM_FOLDER = LeapSalesforce.enum_folder
16
+ else
17
+ ENUM_FOLDER = File.join(LeapSalesforce.lib_folder, 'metadata', 'enum').freeze
18
+ end
14
19
 
15
- # Create Soql enumerations for all objects specified to verify
20
+ # Create Soql enumerations for all objects specified in .leap_salesforce.yml
16
21
  def create
17
- if LeapSalesforce.objects_to_verify.empty?
18
- raise LeapSalesforce::SetupError, 'LeapSalesforce.objects_to_verify is empty. ' \
19
- 'Please set the list of objects you want to verify in .leap_salesforce:soql_objects ' \
22
+ if LeapSalesforce.soql_objects.empty?
23
+ raise LeapSalesforce::SetupError, 'LeapSalesforce.soql_objects is empty. ' \
24
+ 'Please set the list of objects you want to create enums for in .leap_salesforce:soql_objects ' \
20
25
  'and then run task "leaps:create_soql_objects" to create objects'
21
26
  end
22
27
  reset_enum_folder
23
- LeapSalesforce.objects_to_verify.each { |entity| create_picklists_for entity }
28
+ LeapSalesforce.soql_objects.each { |entity| create_picklists_for entity }
24
29
  cleanup_files_created
25
30
  end
26
31
 
@@ -28,16 +33,23 @@ module LeapSalesforce
28
33
  # @param [LeapSalesforce::SoqlData] entity An object representing an object in Salesforce
29
34
  # Object inheriting from SoqlData that has picklists underneath it
30
35
  def create_picklists_for(entity)
31
- soql_object = LeapSalesforce.soql_objects.find { |so| so.class_name == entity.to_s }
32
- raise "Could not find soql object for '#{entity}'" unless soql_object
33
-
36
+ soql_object = entity # LeapSalesforce.soql_objects.find { |so| so.class_name == entity.to_s }
37
+ @soql_data_object = Class.new(SoqlData) do
38
+ soql_object soql_object.backend_name
39
+ end
40
+ @entity_name = entity.class_name
41
+ unless soql_object
42
+ LeapSalesforce.logger.warn "Could not find soql object for '#{@entity_name}', ignoring"
43
+ return
44
+ end
45
+
34
46
  unless soql_object.create_enum != false
35
- puts "Skipping picklists for #{entity}"
47
+ puts "Skipping picklists for #{@entity_name}"
36
48
  return
37
49
  end
38
- puts "Creating picklists for #{entity}"
39
- @entity_name = entity
40
- picklists = entity.picklists
50
+ puts "Creating picklists for #{@entity_name}"
51
+
52
+ picklists = @soql_data_object.picklists
41
53
  puts "#{picklists.count} picklists found"
42
54
  picklists.each do |picklist|
43
55
  if soql_object.excludes?(picklist)
@@ -53,13 +65,20 @@ module LeapSalesforce
53
65
  @picklist = picklist
54
66
  @enum_name = picklist.to_class_name
55
67
  picklist_name = picklist.to_key_name
56
- values = @entity_name.picklist_for(picklist)
68
+ values = @soql_data_object.picklist_for(picklist)
57
69
  @enum_values = {}
58
70
  values.each do |value|
59
71
  @enum_values[value.to_key_name_for(@enum_values)] = value
60
72
  end
61
- content = read_template 'picklist.rb.erb', binding
62
- file = File.join(ENUM_FOLDER, @entity_name.to_s.snakecase, "#{picklist_name}.rb")
73
+ if LeapSalesforce.language == "ruby"
74
+ content = read_template 'picklist.rb.erb', binding
75
+ file = File.join(ENUM_FOLDER, @entity_name.to_s.snakecase, "#{picklist_name}.rb")
76
+ elsif LeapSalesforce.language == 'java'
77
+ content = read_template 'picklist.java.erb', binding
78
+ file = File.join(ENUM_FOLDER, @entity_name.to_s, "#{@enum_name}.java")
79
+ else
80
+ raise LeapSalesforce::SetupError, "Unsupported language '#{LeapSalesforce.language}'"
81
+ end
63
82
  generate_file file, content
64
83
  end
65
84
 
@@ -70,6 +89,8 @@ module LeapSalesforce
70
89
 
71
90
  # Clean up files generated for all picklists
72
91
  def cleanup_files_created
92
+ return unless LeapSalesforce.language == "ruby"
93
+
73
94
  `rubocop -A #{ENUM_FOLDER} --display-only-fail-level-offenses --enable-pending-cops`
74
95
  end
75
96
  end
@@ -0,0 +1,23 @@
1
+ <%= LeapSalesforce.soql_enum_start_text %>.<%= @entity_name %>;
2
+
3
+ /** This file is generated and updated automatically so best not to edit manually
4
+ * Helps handle picklist values for <%= "#{@entity_name}, #{@enum_name}" %>
5
+ */
6
+ public enum <%= @enum_name %> {
7
+ <% @enum_values.each_with_index do |value, index| %>
8
+ <%= value[0].camelize(:upper).to_s %>("<%= value[1] %>")<%= index == @enum_values.length - 1 ? ';' : ',' %><% end%>
9
+
10
+ private String displayName;
11
+
12
+ public String displayName() { return displayName; }
13
+
14
+ @Override public String toString() { return displayName; }
15
+
16
+ <%= @enum_name %>(String displayName) {
17
+ this.displayName = displayName;
18
+ }
19
+
20
+ public static <%= @enum_name %> getRandom() {
21
+ return values()[(int) (Math.random() * values().length)];
22
+ }
23
+ }
@@ -2,24 +2,22 @@
2
2
  import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
3
3
  import com.fasterxml.jackson.annotation.JsonProperty;
4
4
 
5
+ import lombok.Data;
6
+
5
7
  /**
6
8
  * Auto-generated code created by leap_salesforce. Do not manually
7
9
  * update as this can be overwritten when `leap_salesforce create_soql_objects` is run
8
10
  */
9
11
  @JsonIgnoreProperties(ignoreUnknown=true)
12
+ @Data
10
13
  public class <%= @soql_object.class_name %> {
11
14
 
12
15
  <% @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
16
  /**
20
17
  * Label: '<%= field['label'] %>', Type: <%= field['type'] %><%= ", Relationship:" + field['relationshipName'] if field['relationshipName'] %>
21
18
  */
22
- public void set<%= field['name'].camelize(:upper) %>(String <%= field['name'].camelize(:lower) %>) { this.<%= field['name'].camelize(:lower) %> = <%= field['name'].camelize(:lower) %>; }
19
+ @JsonProperty(value="<%= field['name'] %>")
20
+ String <%= field['name'].camelize(:lower) %>;
23
21
  <% end %>
24
22
  }
25
23
 
@@ -11,6 +11,7 @@ CREATE_APP_LINK = 'https://trailhead.salesforce.com/content/learn/projects/autom
11
11
  module LeapSalesforce
12
12
  @config_folder = 'config'
13
13
  @lib_folder = File.join('lib', 'leap_salesforce').freeze
14
+ @enum_folder = nil
14
15
  @objects_to_verify = []
15
16
  @soql_objects = []
16
17
  @client_id = ENV['client_id']
@@ -18,6 +19,7 @@ module LeapSalesforce
18
19
  @password = ENV['password']
19
20
  @language = 'ruby'
20
21
  @soql_field_start_text = ''
22
+ @soql_enum_start_text = ''
21
23
  @environment = nil
22
24
  @logger = Logger.new $stdout
23
25
  @sfdx = false
@@ -124,6 +126,8 @@ module LeapSalesforce
124
126
  attr_accessor :security_token
125
127
  # @return [String] Path where library generated assets are stored. By default lib/leap_salesforce
126
128
  attr_accessor :lib_folder
129
+ # @return [String] Path where generated enum files are stored. By default this is null and just appeneded to lib_folder
130
+ attr_accessor :enum_folder
127
131
  # @return [Array] List of objects to verify metadata for. This includes enums, required values
128
132
  # Changes to these values will need to be version controlled
129
133
  attr_accessor :objects_to_verify
@@ -139,6 +143,9 @@ module LeapSalesforce
139
143
  # classes in the Salesforce object
140
144
  attr_accessor :soql_field_start_text
141
145
 
146
+ # @return [String] Text to be added as start of auto generated Soql enums
147
+ attr_accessor :soql_enum_start_text
148
+
142
149
  # @return [Array] list_of_soql_objects Array describing Soql objects taken from .leap_salesforce.yml
143
150
  def soql_objects=(list_of_soql_objects)
144
151
  @soql_objects = list_of_soql_objects.collect do |soql_object_desc|
@@ -2,5 +2,5 @@
2
2
 
3
3
  module LeapSalesforce
4
4
  # @return [String] Version of leap salesforce
5
- VERSION = '1.4.2'
5
+ VERSION = '1.4.3'
6
6
  end
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.2
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - IQA
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-09-29 00:00:00.000000000 Z
12
+ date: 2024-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -358,6 +358,7 @@ files:
358
358
  - lib/leap_salesforce/generator/templates/config/environments/specific_file.rb.erb
359
359
  - lib/leap_salesforce/generator/templates/config/general.rb.erb
360
360
  - lib/leap_salesforce/generator/templates/factory.rb.erb
361
+ - lib/leap_salesforce/generator/templates/picklist.java.erb
361
362
  - lib/leap_salesforce/generator/templates/picklist.rb.erb
362
363
  - lib/leap_salesforce/generator/templates/soql_object.rb.erb
363
364
  - lib/leap_salesforce/generator/templates/soql_object_field_names.Java.erb