blufin 0.1.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.
- checksums.yaml +7 -0
- data/bin/bf +5 -0
- data/bin/blufin +5 -0
- data/lib/blufin.rb +245 -0
- data/lib/core/code_scanners/common/scanner_common.rb +83 -0
- data/lib/core/code_scanners/common/scanner_java.rb +106 -0
- data/lib/core/code_scanners/scanner_java_embedded_objects.rb +386 -0
- data/lib/core/code_scanners/scanner_java_enums.rb +125 -0
- data/lib/core/code_scanners/scanner_java_source.rb +29 -0
- data/lib/core/code_scanners/scanner_java_tests.rb +157 -0
- data/lib/core/error_handling/schema_error.rb +9 -0
- data/lib/core/error_handling/sql_error.rb +21 -0
- data/lib/core/error_handling/sql_error_handler.rb +149 -0
- data/lib/core/error_handling/yml_error.rb +21 -0
- data/lib/core/error_handling/yml_error_handler.rb +437 -0
- data/lib/core/mysql.rb +347 -0
- data/lib/core/opt.rb +21 -0
- data/lib/core/site/site.rb +26 -0
- data/lib/core/site/site_auth.rb +88 -0
- data/lib/core/site/site_embedded.rb +27 -0
- data/lib/core/site/site_ports.rb +9 -0
- data/lib/core/site/site_resolver.rb +276 -0
- data/lib/core/site/site_services.rb +162 -0
- data/lib/core/site/site_ui.rb +16 -0
- data/lib/core/yml/config/yml_config_validator.rb +219 -0
- data/lib/core/yml/maven/yml_maven_validator.rb +1132 -0
- data/lib/core/yml/resource/yml_resource_validator.rb +154 -0
- data/lib/core/yml/schema/yml_schema_flags.rb +9 -0
- data/lib/core/yml/schema/yml_schema_validator.rb +1850 -0
- data/lib/core/yml/yml_cache_handler.rb +115 -0
- data/lib/core/yml/yml_common.rb +487 -0
- data/lib/core/yml/yml_meta_writer_base.rb +300 -0
- data/lib/core/yml/yml_outputter.rb +307 -0
- data/lib/core/yml/yml_validator_base.rb +630 -0
- data/lib/core/yml_writers/yml_configuration_writer.rb +40 -0
- data/lib/core/yml_writers/yml_java_api_resource_writer.rb +348 -0
- data/lib/core/yml_writers/yml_java_cron_type_writer.rb +113 -0
- data/lib/core/yml_writers/yml_java_css_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_dao_writer.rb +364 -0
- data/lib/core/yml_writers/yml_java_dto_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_embedded_object_writer.rb +968 -0
- data/lib/core/yml_writers/yml_java_enum_writer.rb +161 -0
- data/lib/core/yml_writers/yml_java_js_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_message_type_writer.rb +106 -0
- data/lib/core/yml_writers/yml_java_meta_writer.rb +173 -0
- data/lib/core/yml_writers/yml_java_model_writer.rb +510 -0
- data/lib/core/yml_writers/yml_java_pom_writer.rb +1050 -0
- data/lib/core/yml_writers/yml_java_resource_data_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_sdk_writer.rb +732 -0
- data/lib/core/yml_writers/yml_java_validator_writer.rb +280 -0
- data/lib/core/yml_writers/yml_java_worker_writer.rb +81 -0
- data/lib/core/yml_writers/yml_sql_structure_writer.rb +307 -0
- data/lib/core/yml_writers/yml_sql_template_writer.rb +243 -0
- data/lib/core/yml_writers/yml_vue_service_writer.rb +170 -0
- data/lib/core/yml_writers/yml_writer_base.rb +114 -0
- data/lib/routes/api_list.rb +35 -0
- data/lib/routes/api_meta.rb +59 -0
- data/lib/routes/build.rb +46 -0
- data/lib/routes/create/create_api.rb +35 -0
- data/lib/routes/create/create_ui.rb +84 -0
- data/lib/routes/export.rb +56 -0
- data/lib/routes/generate/generate_api.rb +225 -0
- data/lib/routes/generate/generate_img_favicon.rb +56 -0
- data/lib/routes/generate/generate_img_landing.rb +94 -0
- data/lib/routes/generate/generate_lambda.rb +43 -0
- data/lib/routes/lint.rb +35 -0
- data/lib/routes/mysql_reset.rb +43 -0
- data/lib/routes/release_blufin.rb +351 -0
- data/lib/routes/run.rb +35 -0
- data/lib/version.rb +1 -0
- data/opt/README.MD +2 -0
- data/opt/config/schema.yml +73 -0
- data/opt/config/template.yml +25 -0
- data/opt/sql/data/config/data-client.sql +7 -0
- data/opt/sql/data/config/data-db-configuration-property.sql +47 -0
- data/opt/sql/data/config/data-db-configuration.sql +9 -0
- data/opt/sql/data/config/data-db.sql +175 -0
- data/opt/sql/data/config/data-profile-api.sql +47 -0
- data/opt/sql/data/config/data-profile-cron.sql +0 -0
- data/opt/sql/data/config/data-profile-worker.sql +0 -0
- data/opt/sql/data/config/data-profile.sql +87 -0
- data/opt/sql/data/config/data-project.sql +95 -0
- data/opt/sql/structure/blufin-master-structure-fks.sql +65 -0
- data/opt/sql/structure/blufin-master-structure.sql +97 -0
- data/opt/sql/structure/blufin-mock-structure-fks.sql +38 -0
- data/opt/sql/structure/blufin-mock-structure.sql +98 -0
- data/opt/sql/templates/config/template-client.sql +7 -0
- data/opt/sql/templates/config/template-db-configuration-property.sql +11 -0
- data/opt/sql/templates/config/template-db-configuration.sql +9 -0
- data/opt/sql/templates/config/template-db.sql +21 -0
- data/opt/sql/templates/config/template-profile-api.sql +11 -0
- data/opt/sql/templates/config/template-profile-cron.sql +7 -0
- data/opt/sql/templates/config/template-profile-worker.sql +7 -0
- data/opt/sql/templates/config/template-profile.sql +21 -0
- data/opt/sql/templates/config/template-project.sql +23 -0
- data/opt/yml/api/schema/config/client.yml +14 -0
- data/opt/yml/api/schema/config/db.yml +45 -0
- data/opt/yml/api/schema/config/db_configuration.yml +22 -0
- data/opt/yml/api/schema/config/db_configuration_property.yml +22 -0
- data/opt/yml/api/schema/config/profile.yml +53 -0
- data/opt/yml/api/schema/config/profile_api.yml +22 -0
- data/opt/yml/api/schema/config/profile_cron.yml +14 -0
- data/opt/yml/api/schema/config/profile_worker.yml +14 -0
- data/opt/yml/api/schema/config/project.yml +48 -0
- data/opt/yml/api/schema/mock/mock.yml +99 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum_system.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_linked.yml +43 -0
- data/opt/yml/api/schema/mock/mock_nested_multiple.yml +61 -0
- data/opt/yml/api/schema/mock/mock_nested_single.yml +67 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_deep.yml +32 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_super_deep.yml +17 -0
- metadata +240 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
module Blufin
|
|
2
|
+
|
|
3
|
+
class YmlJavaResourceDataWriter < Blufin::YmlWriterBase
|
|
4
|
+
|
|
5
|
+
SERVICE = Blufin::SiteServices::API
|
|
6
|
+
PACKAGE = Blufin::SiteServices::PACKAGE_AUTO_GENERATED
|
|
7
|
+
|
|
8
|
+
PLACEHOLDER_CLASS = '{{--CLASS--}}'
|
|
9
|
+
PLACEHOLDER_GET = '{{--GET--}}'
|
|
10
|
+
PLACEHOLDER_META_DATA = '{{--GET-META-DATA--}}'
|
|
11
|
+
PLACEHOLDER_DEPTH = '{{--GET-DEPTH--}}'
|
|
12
|
+
PLACEHOLDER_CONTENT_GET = '{{--CONTENT-GET--}}'
|
|
13
|
+
PLACEHOLDER_CONTENT_META_DATA = '{{--CONTENT-META-DATA--}}'
|
|
14
|
+
PLACEHOLDER_CONTENT_DEPTH = '{{--CONTENT-DEPTH--}}'
|
|
15
|
+
|
|
16
|
+
# Initialize the class.
|
|
17
|
+
# @return void
|
|
18
|
+
def initialize(site, schema_resources)
|
|
19
|
+
|
|
20
|
+
raise RuntimeError, 'Could not find valid @schema_resources.' if schema_resources.nil? || !schema_resources.is_a?(Hash)
|
|
21
|
+
|
|
22
|
+
@schema_resources = schema_resources
|
|
23
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
|
24
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
|
25
|
+
@site_name_camel_cased = Blufin::SiteResolver::get_site_name_camel_cased(@site)
|
|
26
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
|
27
|
+
@site_domain_gsub = @site_domain.strip == '' ? '' : "#{@site_domain}."
|
|
28
|
+
@site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
|
|
29
|
+
|
|
30
|
+
@template = <<TEMPLATE
|
|
31
|
+
package #{PLACEHOLDER_PACKAGE};
|
|
32
|
+
|
|
33
|
+
import org.blufin.base.annotations.Singleton;
|
|
34
|
+
import org.blufin.api.base.AbstractResourceData;
|
|
35
|
+
import org.blufin.base.exceptions.BlufinServerException;
|
|
36
|
+
import org.blufin.base.exceptions.BlufinClientException;
|
|
37
|
+
import org.blufin.sdk.exceptions.ResourceNotFoundException;
|
|
38
|
+
import org.blufin.base.enums.SchemaType;
|
|
39
|
+
import org.blufin.sdk.base.PersistentDto;
|
|
40
|
+
import org.blufin.sdk.base.AbstractMetaData;
|
|
41
|
+
import org.blufin.api.base.AbstractValidator;
|
|
42
|
+
import org.blufin.sdk.base.ResourceData;
|
|
43
|
+
import org.blufin.sdk.response.ApiResponse;
|
|
44
|
+
import org.blufin.sdk.rest.GetRequest;#{PLACEHOLDER_IMPORT}
|
|
45
|
+
import org.springframework.stereotype.Service;
|
|
46
|
+
import lombok.Getter;
|
|
47
|
+
|
|
48
|
+
import java.text.MessageFormat;
|
|
49
|
+
|
|
50
|
+
@Service
|
|
51
|
+
public class #{PLACEHOLDER_CLASS} extends AbstractResourceData implements ResourceData {
|
|
52
|
+
|
|
53
|
+
@Getter
|
|
54
|
+
private static final #{PLACEHOLDER_CLASS} instance = new #{PLACEHOLDER_CLASS}();
|
|
55
|
+
|
|
56
|
+
@Singleton
|
|
57
|
+
private #{PLACEHOLDER_CLASS}() {}
|
|
58
|
+
|
|
59
|
+
@Override\n#{PLACEHOLDER_GET}
|
|
60
|
+
|
|
61
|
+
@Override\n#{PLACEHOLDER_META_DATA}
|
|
62
|
+
|
|
63
|
+
@Override\n#{PLACEHOLDER_DEPTH}}
|
|
64
|
+
TEMPLATE
|
|
65
|
+
|
|
66
|
+
@template_execute_get = <<TEMPLATE
|
|
67
|
+
public ApiResponse<? extends PersistentDto> executeGet(String endPoint, GetRequest getRequest) throws BlufinClientException, BlufinServerException {
|
|
68
|
+
|
|
69
|
+
switch (endPoint) {
|
|
70
|
+
|
|
71
|
+
#{PLACEHOLDER_CONTENT_GET}
|
|
72
|
+
default:
|
|
73
|
+
throw new RuntimeException(MessageFormat.format("Unrecognized end-point: {0}", endPoint));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
TEMPLATE
|
|
77
|
+
|
|
78
|
+
@template_get_meta_data = <<TEMPLATE
|
|
79
|
+
public AbstractMetaData getMetaData(String endPoint) throws ResourceNotFoundException {
|
|
80
|
+
|
|
81
|
+
switch (endPoint) {
|
|
82
|
+
|
|
83
|
+
#{PLACEHOLDER_CONTENT_META_DATA}
|
|
84
|
+
default:
|
|
85
|
+
throw new ResourceNotFoundException();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
TEMPLATE
|
|
89
|
+
|
|
90
|
+
@template_get_depth = <<TEMPLATE
|
|
91
|
+
public int getDepth(String table) {
|
|
92
|
+
|
|
93
|
+
switch (table) {
|
|
94
|
+
|
|
95
|
+
#{PLACEHOLDER_CONTENT_DEPTH}
|
|
96
|
+
default:
|
|
97
|
+
throw new RuntimeException(MessageFormat.format("Unrecognized table: {0}", table));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
TEMPLATE
|
|
101
|
+
|
|
102
|
+
@template_execute_get_blank = <<TEMPLATE
|
|
103
|
+
public ApiResponse<? extends PersistentDto> executeGet(String endPoint, GetRequest getRequest) throws BlufinClientException, BlufinServerException {
|
|
104
|
+
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
TEMPLATE
|
|
108
|
+
|
|
109
|
+
@template_get_meta_data_blank = <<TEMPLATE
|
|
110
|
+
public AbstractMetaData getMetaData(String endPoint) throws ResourceNotFoundException {
|
|
111
|
+
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
TEMPLATE
|
|
115
|
+
|
|
116
|
+
@template_get_depth_blank = <<TEMPLATE
|
|
117
|
+
public int getDepth(String table) {
|
|
118
|
+
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
TEMPLATE
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Write the file(s).
|
|
126
|
+
# @return void
|
|
127
|
+
def write
|
|
128
|
+
|
|
129
|
+
resource_data = 'ResourceData'
|
|
130
|
+
|
|
131
|
+
options = [
|
|
132
|
+
[[Blufin::YmlSchemaValidator::APP, Blufin::YmlSchemaValidator::COMMON, Blufin::YmlSchemaValidator::CONFIG], "#{get_java_path(@site, nil, SERVICE, PACKAGE)}/config", "#{@site_name_camel_cased}#{resource_data}", "#{@site_domain_gsub}#{@site_name.gsub('-', '.')}.api.#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.config"],
|
|
133
|
+
[%W(#{Blufin::YmlSchemaValidator::MOCK}), "#{Blufin::Config::get_path('Paths', 'BlufinJava')}/blufin-api/src/test/java/org/blufin/mock", "Mock#{resource_data}", 'org.blufin.mock']
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
# Loops through twice, once to write the App data and once to write the Blufin Data.
|
|
137
|
+
options.each_with_index do |option, idx|
|
|
138
|
+
|
|
139
|
+
opt_schemas = option[0]
|
|
140
|
+
opt_file_location = option[1]
|
|
141
|
+
opt_class_name = option[2]
|
|
142
|
+
opt_package = option[3]
|
|
143
|
+
opt_file = "#{opt_file_location}/#{opt_class_name}.java"
|
|
144
|
+
contents_get = []
|
|
145
|
+
contents_meta_data = []
|
|
146
|
+
contents_depth = []
|
|
147
|
+
schemas_used_get = []
|
|
148
|
+
schemas_used_metadata = []
|
|
149
|
+
|
|
150
|
+
contents = @template
|
|
151
|
+
|
|
152
|
+
# Wipe out all previous file.
|
|
153
|
+
Blufin::Files::delete_file(opt_file) if Blufin::Files::file_exists(opt_file)
|
|
154
|
+
|
|
155
|
+
if get_keys_for_schemas(@schema_resources.keys, opt_schemas).length == 0
|
|
156
|
+
contents = contents.gsub(PLACEHOLDER_GET, @template_execute_get_blank)
|
|
157
|
+
contents = contents.gsub(PLACEHOLDER_META_DATA, @template_get_meta_data_blank)
|
|
158
|
+
contents = contents.gsub(PLACEHOLDER_DEPTH, @template_get_depth_blank)
|
|
159
|
+
else
|
|
160
|
+
contents = contents.gsub(PLACEHOLDER_GET, @template_execute_get)
|
|
161
|
+
contents = contents.gsub(PLACEHOLDER_META_DATA, @template_get_meta_data)
|
|
162
|
+
contents = contents.gsub(PLACEHOLDER_DEPTH, @template_get_depth)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
@schema_resources.each do |schema_table, resource_data|
|
|
166
|
+
|
|
167
|
+
schema = resource_data[:schema]
|
|
168
|
+
|
|
169
|
+
next unless opt_schemas.include?(schema)
|
|
170
|
+
|
|
171
|
+
# Skip if this resource has no HTTP Methods.
|
|
172
|
+
next unless Blufin::YmlCommon::has_at_least_one_http_method(resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL)
|
|
173
|
+
|
|
174
|
+
object = Blufin::Strings::snake_case_to_camel_case(resource_data[:table])
|
|
175
|
+
|
|
176
|
+
contents_depth << " case \"#{resource_data[:resource].gsub('/', '_').gsub('-', '_')}\":"
|
|
177
|
+
contents_depth << " return #{resource_data[:depth]};"
|
|
178
|
+
|
|
179
|
+
if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::GET)
|
|
180
|
+
contents_get << " case \"#{resource_data[:resource]}\":"
|
|
181
|
+
contents_get << " return executeGet(getRequest, #{object}Model.getInstance(), #{idx == 1 ? 'null' : "SchemaType.#{schema.upcase}"});"
|
|
182
|
+
schemas_used_get << schema
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::POST) || resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::PUT) || resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::PATCH) || resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::DELETE)
|
|
186
|
+
contents_meta_data << " case \"#{resource_data[:resource]}\":"
|
|
187
|
+
contents_meta_data << " case \"#{resource_data[:resource]}/list\":" if [Blufin::YmlSchemaValidator::RESOURCE_TYPE_PARENT, Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST].include?(resource_data[:type])
|
|
188
|
+
contents_meta_data << " return #{object}MetaData.getInstance();"
|
|
189
|
+
schemas_used_metadata << schema
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::POST)
|
|
193
|
+
# TODO - POST
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::PUT)
|
|
197
|
+
# TODO - PUT
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::PATCH)
|
|
201
|
+
# TODO - PATCH
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
if resource_data[:methods_internal].has_key?(Blufin::YmlConfigValidator::DELETE)
|
|
205
|
+
# TODO - DELETE
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
contents.gsub!(PLACEHOLDER_CLASS, opt_class_name)
|
|
211
|
+
contents.gsub!(PLACEHOLDER_PACKAGE, opt_package)
|
|
212
|
+
contents.gsub!(PLACEHOLDER_CONTENT_GET, Blufin::YmlCommon::convert_line_array_to_string(contents_get))
|
|
213
|
+
contents.gsub!(PLACEHOLDER_CONTENT_META_DATA, Blufin::YmlCommon::convert_line_array_to_string(contents_meta_data))
|
|
214
|
+
contents.gsub!(PLACEHOLDER_CONTENT_DEPTH, Blufin::YmlCommon::convert_line_array_to_string(contents_depth))
|
|
215
|
+
|
|
216
|
+
# Find out what schemas are being used and import accordingly.
|
|
217
|
+
schemas_import = ''
|
|
218
|
+
schemas_used_get.uniq!.sort! if schemas_used_get.any?
|
|
219
|
+
schemas_used_metadata.uniq!.sort! if schemas_used_get.any?
|
|
220
|
+
if idx == 1
|
|
221
|
+
contents = contents.gsub("\s*package\s+[A-Za-z0-9-_.]+(#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED};)\s*", 'package org.blufin.mock;')
|
|
222
|
+
schemas_import += "\nimport org.blufin.mock.model.*;"
|
|
223
|
+
schemas_import += "\nimport org.blufin.mock.metadata.*;"
|
|
224
|
+
else
|
|
225
|
+
schemas_import += "\nimport #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.api.#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.model.*;" if schemas_used_get.any?
|
|
226
|
+
schemas_import += "\nimport #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.metadata.*;" if schemas_used_metadata.any?
|
|
227
|
+
end
|
|
228
|
+
contents = contents.gsub(PLACEHOLDER_IMPORT, schemas_import)
|
|
229
|
+
|
|
230
|
+
write_file_java(opt_file, Blufin::YmlCommon::convert_string_to_line_array(contents))
|
|
231
|
+
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
private
|
|
237
|
+
|
|
238
|
+
# Returns only the keys for the specified schema(s).
|
|
239
|
+
# @return Array
|
|
240
|
+
def get_keys_for_schemas(keys, schemas)
|
|
241
|
+
keys_for_schema = []
|
|
242
|
+
keys.each do |key|
|
|
243
|
+
if schemas.include?(key.split('.')[0])
|
|
244
|
+
keys_for_schema << key
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
keys_for_schema
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
end
|
|
@@ -0,0 +1,732 @@
|
|
|
1
|
+
module Blufin
|
|
2
|
+
|
|
3
|
+
class YmlJavaSdkWriter < Blufin::YmlWriterBase
|
|
4
|
+
|
|
5
|
+
SERVICE_INTERNAL = Blufin::SiteServices::SDK_INTERNAL
|
|
6
|
+
|
|
7
|
+
PLACEHOLDER_SITE_NAME = '{{--SITE-NAME--}}'
|
|
8
|
+
PLACEHOLDER_SITE_NAME_CAMEL_CASED = '{{--SITE-NAME-CAMEL-CASED--}}'
|
|
9
|
+
PLACEHOLDER_SITE_DOMAIN = '{{--SITE-DOMAIN--}}'
|
|
10
|
+
PLACEHOLDER_CONTENT = '{{--CONTENT--}}'
|
|
11
|
+
PLACEHOLDER_SERVICE = '{{--SERVICE--}}'
|
|
12
|
+
PLACEHOLDER_SERVICE_GETTERS = '{{--SERVICE-GETTERS--}}'
|
|
13
|
+
PLACEHOLDER_END_POINT = '{{--END-POINT--}}'
|
|
14
|
+
PLACEHOLDER_ENUM = '{{--ENUM--}}'
|
|
15
|
+
PLACEHOLDER_BASE_IMPORT = '{{--BASE-IMPORT--}}'
|
|
16
|
+
PLACEHOLDER_OVERRIDE = '{{--OVERRIDE--}}'
|
|
17
|
+
PLACEHOLDER_OVERRIDE_TOP = '{{--OVERRIDE-TOP-}}'
|
|
18
|
+
|
|
19
|
+
# Initialize the class.
|
|
20
|
+
# @return void
|
|
21
|
+
def initialize(site, schema_data, schema_resources)
|
|
22
|
+
|
|
23
|
+
@schema_data = schema_data
|
|
24
|
+
@schema_resources = schema_resources
|
|
25
|
+
|
|
26
|
+
raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
|
|
27
|
+
raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash)
|
|
28
|
+
|
|
29
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
|
30
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
|
31
|
+
@site_name_camel_cased = Blufin::SiteResolver::get_site_name_camel_cased(@site)
|
|
32
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
|
33
|
+
@site_domain_gsub = @site_domain.strip == '' ? '' : "#{@site_domain}."
|
|
34
|
+
@site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
|
|
35
|
+
|
|
36
|
+
@path_base = "#{get_java_path(@site, nil, SERVICE_INTERNAL, 'base')}"
|
|
37
|
+
@path_service = "#{get_java_path(@site, nil, SERVICE_INTERNAL, 'service')}"
|
|
38
|
+
|
|
39
|
+
@embedded_data = Blufin::SiteEmbedded::get_data
|
|
40
|
+
@embedded_path = "#{Blufin::Config::get_path('Paths', 'BlufinJava')}/#{Blufin::ScannerJavaEmbeddedObjects::PATH_TO_EMBEDDED}"
|
|
41
|
+
@embedded_package = 'org.blufin.sdk.embedded'
|
|
42
|
+
@embedded_objects = Blufin::SiteAuth::AUTHENTICATION_LEVELS[Blufin::SiteAuth::get_auth_level]
|
|
43
|
+
|
|
44
|
+
@base_import_schemas = []
|
|
45
|
+
|
|
46
|
+
@auth_level = Blufin::SiteAuth::get_auth_level
|
|
47
|
+
|
|
48
|
+
# Wipe out all previous sdk.base files.
|
|
49
|
+
paths_to_wipe_out = [@path_base]
|
|
50
|
+
paths_to_wipe_out.each do |path_to_wipe_out|
|
|
51
|
+
if Blufin::Files::path_exists(path_to_wipe_out)
|
|
52
|
+
if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
|
|
53
|
+
Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Wipe out all previous sdk.service.{schema} files.
|
|
59
|
+
Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
|
|
60
|
+
paths_to_wipe_out = %W(
|
|
61
|
+
#{get_java_path(@site, schema, SERVICE_INTERNAL, 'client')}
|
|
62
|
+
#{get_java_path(@site, schema, SERVICE_INTERNAL, 'field')}
|
|
63
|
+
#{get_java_path(@site, schema, SERVICE_INTERNAL, 'filter')}
|
|
64
|
+
#{get_java_path(@site, schema, SERVICE_INTERNAL, 'refiner')}
|
|
65
|
+
#{get_java_path(@site, schema, SERVICE_INTERNAL, 'service')}
|
|
66
|
+
#{get_java_path(@site, schema, SERVICE_INTERNAL, 'sort')}
|
|
67
|
+
)
|
|
68
|
+
paths_to_wipe_out.each do |path_to_wipe_out|
|
|
69
|
+
if Blufin::Files::path_exists(path_to_wipe_out)
|
|
70
|
+
if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
|
|
71
|
+
Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
@template_base = <<TEMPLATE
|
|
78
|
+
package #{PLACEHOLDER_PACKAGE};
|
|
79
|
+
|
|
80
|
+
import org.blufin.sdk.base.ResourceData;
|
|
81
|
+
import org.blufin.sdk.service.BlufinApiService;
|
|
82
|
+
import org.blufin.sdk.service.credentials.ApiCredentialsHttp;
|
|
83
|
+
import org.blufin.sdk.service.credentials.ApiCredentialsInternal;
|
|
84
|
+
import org.springframework.stereotype.Service;
|
|
85
|
+
#{PLACEHOLDER_BASE_IMPORT}
|
|
86
|
+
@Service
|
|
87
|
+
public class #{PLACEHOLDER_CLASS} extends BlufinApiService {
|
|
88
|
+
|
|
89
|
+
public void initialize(ResourceData resourceLocator) {
|
|
90
|
+
|
|
91
|
+
initializeParent(new ApiCredentialsInternal(resourceLocator));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public void initialize(String authorizationHeader, String apiUri) {
|
|
95
|
+
|
|
96
|
+
initializeParent(new ApiCredentialsHttp(authorizationHeader, apiUri));
|
|
97
|
+
}
|
|
98
|
+
#{PLACEHOLDER_SERVICE_GETTERS}}
|
|
99
|
+
TEMPLATE
|
|
100
|
+
|
|
101
|
+
@template_service_getter = <<TEMPLATE
|
|
102
|
+
|
|
103
|
+
public #{PLACEHOLDER_SERVICE}Service get#{PLACEHOLDER_SERVICE}Service() {
|
|
104
|
+
|
|
105
|
+
return new #{PLACEHOLDER_SERVICE}Service(getApiCredentials());
|
|
106
|
+
}
|
|
107
|
+
TEMPLATE
|
|
108
|
+
|
|
109
|
+
@template_service_outer = <<TEMPLATE
|
|
110
|
+
package #{PLACEHOLDER_PACKAGE};
|
|
111
|
+
|
|
112
|
+
import org.blufin.sdk.base.AbstractService;
|
|
113
|
+
import org.blufin.base.helper.IdSet;
|
|
114
|
+
import org.blufin.sdk.service.credentials.ApiCredentials;#{PLACEHOLDER_IMPORT}
|
|
115
|
+
import org.blufin.sdk.request.IdSetGetRequest;
|
|
116
|
+
import org.blufin.sdk.request.PaginatedGetRequest;
|
|
117
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{PLACEHOLDER_SERVICE};
|
|
118
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.field.#{PLACEHOLDER_SERVICE}Field;
|
|
119
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.metadata.#{PLACEHOLDER_SERVICE}MetaData;
|
|
120
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.refiner.#{PLACEHOLDER_SERVICE}Refiner;
|
|
121
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.sort.#{PLACEHOLDER_SERVICE}Sort;
|
|
122
|
+
|
|
123
|
+
public class #{PLACEHOLDER_CLASS} implements AbstractService {
|
|
124
|
+
|
|
125
|
+
private final ApiCredentials apiCredentials;
|
|
126
|
+
|
|
127
|
+
public #{PLACEHOLDER_CLASS}(ApiCredentials apiCredentials) {
|
|
128
|
+
|
|
129
|
+
this.apiCredentials = apiCredentials;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#{PLACEHOLDER_CONTENT}}
|
|
133
|
+
TEMPLATE
|
|
134
|
+
|
|
135
|
+
@template_service = <<TEMPLATE
|
|
136
|
+
#{PLACEHOLDER_OVERRIDE_TOP}public PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner> get() {
|
|
137
|
+
|
|
138
|
+
return new PaginatedGetRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), #{PLACEHOLDER_SERVICE}Refiner.class);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#{PLACEHOLDER_OVERRIDE}public IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort> get(IdSet idSet) {
|
|
142
|
+
|
|
143
|
+
return new IdSetGetRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), idSet);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#{PLACEHOLDER_OVERRIDE}public IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort> get(int id) {
|
|
147
|
+
|
|
148
|
+
return new IdSetGetRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), new IdSet(id));
|
|
149
|
+
}
|
|
150
|
+
TEMPLATE
|
|
151
|
+
|
|
152
|
+
@template_service_account = <<TEMPLATE
|
|
153
|
+
#{PLACEHOLDER_OVERRIDE_TOP}public AccountRequest<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> get() {
|
|
154
|
+
|
|
155
|
+
return new AccountRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), #{PLACEHOLDER_SERVICE}Refiner.class);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#{PLACEHOLDER_OVERRIDE}public AccountRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(IdSet idSet) {
|
|
159
|
+
|
|
160
|
+
return new AccountRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), idSet);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
#{PLACEHOLDER_OVERRIDE}public AccountRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(int id) {
|
|
164
|
+
|
|
165
|
+
return new AccountRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), new IdSet(id));
|
|
166
|
+
}
|
|
167
|
+
TEMPLATE
|
|
168
|
+
|
|
169
|
+
@template_service_account_user = <<TEMPLATE
|
|
170
|
+
#{PLACEHOLDER_OVERRIDE_TOP}public AccountUserRequest<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> get() {
|
|
171
|
+
|
|
172
|
+
return new AccountUserRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), #{PLACEHOLDER_SERVICE}Refiner.class);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#{PLACEHOLDER_OVERRIDE}public AccountUserRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(IdSet idSet) {
|
|
176
|
+
|
|
177
|
+
return new AccountUserRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), idSet);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#{PLACEHOLDER_OVERRIDE}public AccountUserRequest<IdSetGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort>> get(int id) {
|
|
181
|
+
|
|
182
|
+
return new AccountUserRequest<>(apiCredentials, "#{PLACEHOLDER_END_POINT}", #{PLACEHOLDER_SERVICE}.class, #{PLACEHOLDER_SERVICE}MetaData.getInstance(), new IdSet(id));
|
|
183
|
+
}
|
|
184
|
+
TEMPLATE
|
|
185
|
+
|
|
186
|
+
@template_field = <<TEMPLATE
|
|
187
|
+
package #{PLACEHOLDER_PACKAGE};
|
|
188
|
+
|
|
189
|
+
import org.blufin.sdk.base.AbstractField;
|
|
190
|
+
|
|
191
|
+
public enum #{PLACEHOLDER_CLASS} implements AbstractField {
|
|
192
|
+
#{PLACEHOLDER_CONTENT}
|
|
193
|
+
|
|
194
|
+
private final String fieldName;
|
|
195
|
+
|
|
196
|
+
#{PLACEHOLDER_CLASS}(String fieldName) {
|
|
197
|
+
|
|
198
|
+
this.fieldName = fieldName;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@Override
|
|
202
|
+
public String getFieldName() {
|
|
203
|
+
|
|
204
|
+
return fieldName;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
TEMPLATE
|
|
208
|
+
|
|
209
|
+
@template_filter = <<TEMPLATE
|
|
210
|
+
package #{PLACEHOLDER_PACKAGE};
|
|
211
|
+
|
|
212
|
+
import org.blufin.sdk.base.AbstractFilter;
|
|
213
|
+
|
|
214
|
+
public enum #{PLACEHOLDER_CLASS} implements AbstractFilter {
|
|
215
|
+
#{PLACEHOLDER_CONTENT}
|
|
216
|
+
|
|
217
|
+
private final String fieldName;
|
|
218
|
+
|
|
219
|
+
#{PLACEHOLDER_CLASS}(String fieldName) {
|
|
220
|
+
|
|
221
|
+
this.fieldName = fieldName;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@Override
|
|
225
|
+
public String getFieldName() {
|
|
226
|
+
|
|
227
|
+
return fieldName;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
TEMPLATE
|
|
231
|
+
|
|
232
|
+
@template_sort = <<TEMPLATE
|
|
233
|
+
package #{PLACEHOLDER_PACKAGE};
|
|
234
|
+
|
|
235
|
+
import org.blufin.sdk.base.AbstractSort;
|
|
236
|
+
|
|
237
|
+
public enum #{PLACEHOLDER_CLASS} implements AbstractSort {
|
|
238
|
+
#{PLACEHOLDER_CONTENT}
|
|
239
|
+
|
|
240
|
+
private final String fieldName;
|
|
241
|
+
|
|
242
|
+
#{PLACEHOLDER_CLASS}(String fieldName) {
|
|
243
|
+
|
|
244
|
+
this.fieldName = fieldName;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
@Override
|
|
248
|
+
public String getFieldName() {
|
|
249
|
+
|
|
250
|
+
return fieldName;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
@Override
|
|
254
|
+
public String toString() {
|
|
255
|
+
|
|
256
|
+
return this.name();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
TEMPLATE
|
|
260
|
+
|
|
261
|
+
@template_refiner = <<TEMPLATE
|
|
262
|
+
package #{PLACEHOLDER_PACKAGE};
|
|
263
|
+
|
|
264
|
+
import org.blufin.base.annotations.NestedRefiner;
|
|
265
|
+
import org.blufin.sdk.base.AbstractRefiner;
|
|
266
|
+
import org.blufin.sdk.base.Refiner;
|
|
267
|
+
import org.blufin.sdk.filters.dynamic.*;
|
|
268
|
+
import org.blufin.sdk.request.PaginatedGetRequest;
|
|
269
|
+
import org.blufin.sdk.filters.Filter;
|
|
270
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{PLACEHOLDER_SERVICE};
|
|
271
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.field.#{PLACEHOLDER_SERVICE}Field;
|
|
272
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.filter.#{PLACEHOLDER_SERVICE}Filter;
|
|
273
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.sort.#{PLACEHOLDER_SERVICE}Sort;#{PLACEHOLDER_BASE_IMPORT}
|
|
274
|
+
import java.util.List;
|
|
275
|
+
|
|
276
|
+
public class #{PLACEHOLDER_CLASS} extends Refiner<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> implements AbstractRefiner {
|
|
277
|
+
|
|
278
|
+
public #{PLACEHOLDER_SERVICE}Refiner(List<Filter> filters, PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner> originalRequest) {
|
|
279
|
+
|
|
280
|
+
super(filters, originalRequest);
|
|
281
|
+
}
|
|
282
|
+
#{PLACEHOLDER_CONTENT}}
|
|
283
|
+
TEMPLATE
|
|
284
|
+
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# Write the file(s).
|
|
288
|
+
# @return void
|
|
289
|
+
def write
|
|
290
|
+
|
|
291
|
+
write_service
|
|
292
|
+
write_meta
|
|
293
|
+
write_base
|
|
294
|
+
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
private
|
|
298
|
+
|
|
299
|
+
# Writes all the Services -> IE: SaleService
|
|
300
|
+
# @return void
|
|
301
|
+
def write_service
|
|
302
|
+
|
|
303
|
+
@schema_resources.each do |data|
|
|
304
|
+
|
|
305
|
+
data = data[1]
|
|
306
|
+
schema = data[:schema]
|
|
307
|
+
table = data[:table]
|
|
308
|
+
service = Blufin::Strings::snake_case_to_camel_case(data[:table])
|
|
309
|
+
class_name = "#{service}Service"
|
|
310
|
+
class_auth = Blufin::SiteAuth::get_auth_level_for_table(schema, table)
|
|
311
|
+
import_statements = []
|
|
312
|
+
contents = @template_service_outer
|
|
313
|
+
overridden = @embedded_objects.include?(table)
|
|
314
|
+
|
|
315
|
+
import_statements << 'import org.blufin.base.annotations.Embedded;' if overridden
|
|
316
|
+
|
|
317
|
+
case class_auth
|
|
318
|
+
when Blufin::SiteAuth::LEVEL_NONE
|
|
319
|
+
contents_inner = @template_service
|
|
320
|
+
when Blufin::SiteAuth::LEVEL_ACCOUNT
|
|
321
|
+
import_statements << 'import org.blufin.sdk.request.type.AccountRequest;'
|
|
322
|
+
contents_inner = @template_service_account
|
|
323
|
+
when Blufin::SiteAuth::LEVEL_ACCOUNT_USER
|
|
324
|
+
import_statements << 'import org.blufin.sdk.request.type.AccountUserRequest;'
|
|
325
|
+
contents_inner = @template_service_account_user
|
|
326
|
+
else
|
|
327
|
+
raise RuntimeError, "Unrecognized AuthLevel for table: #{class_auth}"
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
contents = contents.gsub(PLACEHOLDER_CONTENT, contents_inner)
|
|
331
|
+
contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, "service", SERVICE_INTERNAL))
|
|
332
|
+
contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
|
|
333
|
+
contents = contents.gsub(PLACEHOLDER_SERVICE, service)
|
|
334
|
+
contents = contents.gsub(PLACEHOLDER_END_POINT, data[:resource])
|
|
335
|
+
contents = contents.gsub(PLACEHOLDER_OVERRIDE_TOP, overridden ? " @Embedded\n " : ' ')
|
|
336
|
+
contents = contents.gsub(PLACEHOLDER_OVERRIDE, overridden ? "@Embedded\n " : '')
|
|
337
|
+
contents = contents.gsub(PLACEHOLDER_IMPORT, import_statements.any? ? "\n#{import_statements.join("\n")}" : '')
|
|
338
|
+
contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
|
|
339
|
+
contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
|
|
340
|
+
|
|
341
|
+
write_file_java("#{@path_service}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
|
|
342
|
+
|
|
343
|
+
@base_import_schemas << schema unless @base_import_schemas.include?(schema) || schema == Blufin::YmlSchemaValidator::MOCK
|
|
344
|
+
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# Writes all the Field, Refiner + Sort classes -> IE: SaleField, SaleRefiner, SaleSort
|
|
350
|
+
# @return void
|
|
351
|
+
def write_meta
|
|
352
|
+
|
|
353
|
+
@schema_resources.each do |data|
|
|
354
|
+
|
|
355
|
+
data = data[1]
|
|
356
|
+
|
|
357
|
+
write_field(data)
|
|
358
|
+
write_filter(data)
|
|
359
|
+
write_sort(data)
|
|
360
|
+
write_refiner(data)
|
|
361
|
+
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
# Write FIELD Classes.
|
|
367
|
+
# @return void
|
|
368
|
+
def write_field(data)
|
|
369
|
+
|
|
370
|
+
content_data = []
|
|
371
|
+
content = "\n"
|
|
372
|
+
package = 'field'
|
|
373
|
+
schema = data[:schema]
|
|
374
|
+
table = data[:table]
|
|
375
|
+
service = Blufin::Strings::snake_case_to_camel_case(data[:table])
|
|
376
|
+
class_name = "#{service}Field"
|
|
377
|
+
contents = @template_field
|
|
378
|
+
contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
|
|
379
|
+
contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
|
|
380
|
+
field_data = @schema_data[data[:schema]][data[:table]]
|
|
381
|
+
|
|
382
|
+
field_data.keys.each do |key|
|
|
383
|
+
next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[(link)?\]\z/
|
|
384
|
+
content_data << [Blufin::YmlCommon::extract_field_name(key)]
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
content_data.each_with_index do |cd, idx|
|
|
388
|
+
comma_or_not = (idx == (content_data.length - 1)) ? ';' : ",\n"
|
|
389
|
+
content += " #{cd[0].upcase}(\"#{table}.#{cd[0]}\")#{comma_or_not}"
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
contents = contents.gsub(PLACEHOLDER_CONTENT, content)
|
|
393
|
+
|
|
394
|
+
write_file_java("#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
|
|
395
|
+
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
# Write FILTER Classes.
|
|
399
|
+
# @return void
|
|
400
|
+
def write_filter(data)
|
|
401
|
+
|
|
402
|
+
content_data = []
|
|
403
|
+
content = "\n"
|
|
404
|
+
package = 'filter'
|
|
405
|
+
schema = data[:schema]
|
|
406
|
+
table = data[:table]
|
|
407
|
+
service = Blufin::Strings::snake_case_to_camel_case(data[:table])
|
|
408
|
+
|
|
409
|
+
class_name = "#{service}Filter"
|
|
410
|
+
|
|
411
|
+
contents = @template_filter
|
|
412
|
+
contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
|
|
413
|
+
contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
|
|
414
|
+
|
|
415
|
+
field_data = @schema_data[data[:schema]][data[:table]]
|
|
416
|
+
field_data.each do |key, data|
|
|
417
|
+
next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[(link)?\]\z/
|
|
418
|
+
next if data.has_key?(Blufin::YmlSchemaValidator::ENCRYPTED)
|
|
419
|
+
content_data << [Blufin::YmlCommon::extract_field_name(key)]
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
content_data.each_with_index do |cd, idx|
|
|
423
|
+
comma_or_not = (idx == (content_data.length - 1)) ? ';' : ",\n"
|
|
424
|
+
content += " #{cd[0].upcase}(\"#{table}.#{cd[0]}\")#{comma_or_not}"
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
contents = contents.gsub(PLACEHOLDER_CONTENT, content)
|
|
428
|
+
|
|
429
|
+
write_file_java("#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
|
|
430
|
+
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
# Write SORT Classes.
|
|
434
|
+
# @return void
|
|
435
|
+
def write_sort(data)
|
|
436
|
+
|
|
437
|
+
content_data = []
|
|
438
|
+
content = "\n"
|
|
439
|
+
package = 'sort'
|
|
440
|
+
table = data[:table]
|
|
441
|
+
schema = data[:schema]
|
|
442
|
+
service = Blufin::Strings::snake_case_to_camel_case(data[:table])
|
|
443
|
+
class_name = "#{service}Sort"
|
|
444
|
+
contents = @template_sort
|
|
445
|
+
contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
|
|
446
|
+
contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
|
|
447
|
+
field_data = @schema_data[data[:schema]][data[:table]]
|
|
448
|
+
|
|
449
|
+
field_data.each_with_index do |(key, data_inner), idx|
|
|
450
|
+
next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[(link)?\]\z/
|
|
451
|
+
next if data_inner.has_key?(Blufin::YmlSchemaValidator::ENCRYPTED)
|
|
452
|
+
next if [
|
|
453
|
+
Blufin::YmlSchemaValidator::TYPE_BOOLEAN,
|
|
454
|
+
Blufin::YmlSchemaValidator::TYPE_TEXT,
|
|
455
|
+
Blufin::YmlSchemaValidator::TYPE_TEXT_LONG
|
|
456
|
+
].include?(data_inner['type'])
|
|
457
|
+
content_data << [Blufin::YmlCommon::extract_field_name(key)]
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
content_data.each_with_index do |cd, idx|
|
|
461
|
+
comma_or_not = (idx == (content_data.length - 1)) ? ';' : ",\n"
|
|
462
|
+
content += " #{cd[0].upcase}(\"#{table}.#{cd[0]}\")#{comma_or_not}"
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
contents = contents.gsub(PLACEHOLDER_CONTENT, content)
|
|
466
|
+
|
|
467
|
+
write_file_java("#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
|
|
468
|
+
|
|
469
|
+
end
|
|
470
|
+
|
|
471
|
+
# Write REFINER Classes.
|
|
472
|
+
# @return void
|
|
473
|
+
def write_refiner(data)
|
|
474
|
+
|
|
475
|
+
@content = "\n"
|
|
476
|
+
@content_nested = {}
|
|
477
|
+
package = 'refiner'
|
|
478
|
+
schema = data[:schema]
|
|
479
|
+
table = data[:table]
|
|
480
|
+
service = Blufin::Strings::snake_case_to_camel_case(data[:table])
|
|
481
|
+
class_name = "#{service}Refiner"
|
|
482
|
+
full_file_path = "#{get_java_path(@site, schema, SERVICE_INTERNAL, package)}/#{class_name}.java"
|
|
483
|
+
@content_data_import = []
|
|
484
|
+
@content_data_master = {}
|
|
485
|
+
|
|
486
|
+
get_refiner_content(schema, table)
|
|
487
|
+
|
|
488
|
+
# Sort Hash by keys (alphabetically).
|
|
489
|
+
@content_data_master = Hash[@content_data_master.sort_by { |key, val| key }]
|
|
490
|
+
@content_data_master.each do |first_key, content_data|
|
|
491
|
+
write_refiner_content(first_key, content_data, service)
|
|
492
|
+
break
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
contents = @template_refiner
|
|
496
|
+
contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, schema, package, SERVICE_INTERNAL))
|
|
497
|
+
contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
|
|
498
|
+
|
|
499
|
+
base_import_statements = "\n"
|
|
500
|
+
|
|
501
|
+
@content_data_import.uniq!
|
|
502
|
+
@content_data_import.sort!
|
|
503
|
+
@content_data_import.each { |content_import_statement| base_import_statements += "#{content_import_statement}\n" }
|
|
504
|
+
|
|
505
|
+
@content_nested.each do |key, data|
|
|
506
|
+
key_split = key.split('.')
|
|
507
|
+
nest_level = key_split[0]
|
|
508
|
+
nc_cc = Blufin::Strings::snake_case_to_camel_case(key_split[2])
|
|
509
|
+
content = <<CLASS
|
|
510
|
+
@NestedRefiner
|
|
511
|
+
public static class #{nc_cc}Refiner extends Refiner<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>> implements AbstractRefiner {
|
|
512
|
+
|
|
513
|
+
public #{nc_cc}Refiner(List<Filter> filters, PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner> originalRequest) {
|
|
514
|
+
|
|
515
|
+
super(filters, originalRequest);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
#{PLACEHOLDER_CONTENT} }
|
|
519
|
+
|
|
520
|
+
CLASS
|
|
521
|
+
content = content.gsub(PLACEHOLDER_CONTENT, data.chomp)
|
|
522
|
+
@content += content
|
|
523
|
+
end
|
|
524
|
+
|
|
525
|
+
contents = contents.gsub(PLACEHOLDER_CONTENT, @content.chomp)
|
|
526
|
+
contents = contents.gsub(PLACEHOLDER_SERVICE, service)
|
|
527
|
+
contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
|
|
528
|
+
contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
|
|
529
|
+
contents = contents.gsub(PLACEHOLDER_BASE_IMPORT, base_import_statements)
|
|
530
|
+
|
|
531
|
+
write_file_java(full_file_path, Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
|
|
532
|
+
|
|
533
|
+
end
|
|
534
|
+
|
|
535
|
+
# Gets refiner content as a Hash of Arrays.
|
|
536
|
+
# @return string
|
|
537
|
+
def get_refiner_content(schema, table, nest_level = 1)
|
|
538
|
+
|
|
539
|
+
content_data = []
|
|
540
|
+
content_import = []
|
|
541
|
+
|
|
542
|
+
field_data = @schema_data[schema][table]
|
|
543
|
+
field_data.keys.each do |key|
|
|
544
|
+
|
|
545
|
+
field_to_match = key.include?('.') ? key.split('.')[1] : key
|
|
546
|
+
filterable_extra = nil
|
|
547
|
+
|
|
548
|
+
# If this is a LINK field, skip.
|
|
549
|
+
# TODO - 12/15/18 - Probably need to make changes here when we need to support Linked objects.
|
|
550
|
+
next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[link\]\z/
|
|
551
|
+
|
|
552
|
+
# If this is a nested SINGLE/MULTIPLE, handle it.
|
|
553
|
+
if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/
|
|
554
|
+
key_split = key.gsub(/\[\]$/, '').split('.')
|
|
555
|
+
content_data << ["#{nest_level + 1}.#{schema}.#{key_split[1]}"]
|
|
556
|
+
get_refiner_content(schema, key_split[1], nest_level + 1)
|
|
557
|
+
next
|
|
558
|
+
end
|
|
559
|
+
|
|
560
|
+
# If this field is ENCRYPTED, skip.
|
|
561
|
+
next if @schema_data[schema][table][key].has_key?(Blufin::YmlSchemaValidator::ENCRYPTED)
|
|
562
|
+
|
|
563
|
+
@type = @schema_data[schema][table][key][Blufin::YmlSchemaValidator::TYPE]
|
|
564
|
+
|
|
565
|
+
# Skip Transient Objects.
|
|
566
|
+
next if [Blufin::ScannerJavaEmbeddedObjects::OBJECT].include?(@type)
|
|
567
|
+
|
|
568
|
+
enum_class = nil
|
|
569
|
+
|
|
570
|
+
begin
|
|
571
|
+
overridden = @embedded_data[table][:data].keys.include?(key)
|
|
572
|
+
@content_data_import << 'import org.blufin.base.annotations.Embedded;'
|
|
573
|
+
rescue
|
|
574
|
+
overridden = false
|
|
575
|
+
end
|
|
576
|
+
|
|
577
|
+
if @type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
|
578
|
+
filter = 'FilterBoolean'
|
|
579
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_DATE
|
|
580
|
+
# Must come BEFORE ..DATETIME_TYPES.include?(@type) because the latter included DATE as well.
|
|
581
|
+
filter = 'FilterDate'
|
|
582
|
+
elsif Blufin::YmlSchemaValidator::DATETIME_TYPES.include?(@type)
|
|
583
|
+
filter = 'FilterDateTime'
|
|
584
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL
|
|
585
|
+
filter = 'FilterDecimal'
|
|
586
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_BIG
|
|
587
|
+
filter = 'FilterIntegerBig'
|
|
588
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_TINY
|
|
589
|
+
filter = 'FilterIntegerTiny'
|
|
590
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
|
|
591
|
+
filter = 'FilterIntegerSmall'
|
|
592
|
+
elsif Blufin::YmlSchemaValidator::INT_TYPES.include?(@type)
|
|
593
|
+
filter = 'FilterInteger'
|
|
594
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT
|
|
595
|
+
filter = 'FilterText'
|
|
596
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT_LONG
|
|
597
|
+
filter = 'FilterTextLong'
|
|
598
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM || @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM || @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
|
599
|
+
filter = 'FilterEnum'
|
|
600
|
+
if @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
|
601
|
+
enum_class = "#{Blufin::Strings::snake_case_to_camel_case(table)}#{Blufin::Strings::snake_case_to_camel_case(key)}"
|
|
602
|
+
enum_import = "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.enums.#{PLACEHOLDER_ENUM};"
|
|
603
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM
|
|
604
|
+
|
|
605
|
+
# TODO - Need to fix this. Enums need to be handled in a way that they resolve to a package/path (not something hard-coded).
|
|
606
|
+
|
|
607
|
+
enum_class = Blufin::YmlCommon::enum_name_extractor(@type)
|
|
608
|
+
enum_import = "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.enums.#{PLACEHOLDER_ENUM};"
|
|
609
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
|
610
|
+
enum_class = Blufin::YmlCommon::enum_name_extractor(@type)
|
|
611
|
+
enum_import = "import #{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS}.#{PLACEHOLDER_ENUM};"
|
|
612
|
+
else
|
|
613
|
+
raise RuntimeError, "'enum_string' doesn't match regex --> #{@type}"
|
|
614
|
+
end
|
|
615
|
+
enum_class = enum_class.slice(0, 1).upcase + enum_class.slice(1..-1)
|
|
616
|
+
filterable_extra = ", #{enum_class}"
|
|
617
|
+
@content_data_import << enum_import.gsub(PLACEHOLDER_ENUM, enum_class)
|
|
618
|
+
enum_class = ", #{enum_class}"
|
|
619
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
|
|
620
|
+
filter = 'FilterVarchar'
|
|
621
|
+
else
|
|
622
|
+
raise RuntimeError, "Unrecognized type in #{__FILE__} or field: #{key} \xe2\x86\x92 #{@type}"
|
|
623
|
+
end
|
|
624
|
+
|
|
625
|
+
key_cleaned = Blufin::YmlCommon::extract_field_name(key)
|
|
626
|
+
|
|
627
|
+
content_data << [filter, Blufin::Strings::snake_case_to_camel_case_lower(key_cleaned), key_cleaned.upcase, filterable_extra, overridden]
|
|
628
|
+
|
|
629
|
+
end
|
|
630
|
+
|
|
631
|
+
@content_data_master["#{nest_level}.#{schema}.#{table}"] = content_data
|
|
632
|
+
|
|
633
|
+
end
|
|
634
|
+
|
|
635
|
+
# Adds method data to @content & @content_nested Arrays.
|
|
636
|
+
# @return void
|
|
637
|
+
def write_refiner_content(content_key, content_data, service_inner, nest_level = 1)
|
|
638
|
+
|
|
639
|
+
nest_space = nest_level == 1 ? ' ' : ' '
|
|
640
|
+
|
|
641
|
+
content_data.each do |cd|
|
|
642
|
+
|
|
643
|
+
if cd.length == 1
|
|
644
|
+
cd_split = cd[0].split('.')
|
|
645
|
+
cd_cc = Blufin::Strings::snake_case_to_camel_case(cd_split[2])
|
|
646
|
+
cd_ccl = Blufin::Strings::snake_case_to_camel_case_lower(cd_split[2])
|
|
647
|
+
@content_data_import << "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.filter.#{cd_cc}Filter;"
|
|
648
|
+
write_refiner_content(cd[0], @content_data_master[cd[0]], cd_cc, nest_level + 1)
|
|
649
|
+
content = <<METHOD
|
|
650
|
+
#{nest_space}public #{PLACEHOLDER_SERVICE}Refiner.#{cd_cc}Refiner #{cd_ccl}() {
|
|
651
|
+
|
|
652
|
+
#{nest_space} return new #{PLACEHOLDER_SERVICE}Refiner.#{cd_cc}Refiner(getFilters(), getOriginalRequest());
|
|
653
|
+
#{nest_space}}
|
|
654
|
+
|
|
655
|
+
METHOD
|
|
656
|
+
if nest_level == 1
|
|
657
|
+
@content += content
|
|
658
|
+
else
|
|
659
|
+
@content_nested[content_key] = '' if @content_nested[cd].nil?
|
|
660
|
+
@content_nested[content_key] += content
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
next
|
|
664
|
+
end
|
|
665
|
+
|
|
666
|
+
content = ''
|
|
667
|
+
content += "#{nest_space}#{Blufin::ScannerJavaEmbeddedObjects::EMBEDDED_ANNOTATION}\n" if cd[4]
|
|
668
|
+
content += <<METHOD
|
|
669
|
+
#{nest_space}public #{cd[0]}<PaginatedGetRequest<#{PLACEHOLDER_SERVICE}, #{PLACEHOLDER_SERVICE}Field, #{PLACEHOLDER_SERVICE}Sort, #{PLACEHOLDER_SERVICE}Refiner>#{cd[3]}> #{cd[1]}() {
|
|
670
|
+
|
|
671
|
+
#{nest_space} return new #{cd[0]}<>(#{service_inner}Filter.#{cd[2]}, getFilters(), getOriginalRequest());
|
|
672
|
+
#{nest_space}}
|
|
673
|
+
|
|
674
|
+
METHOD
|
|
675
|
+
if nest_level == 1
|
|
676
|
+
@content += content
|
|
677
|
+
else
|
|
678
|
+
@content_nested[content_key] = '' if @content_nested[content_key].nil?
|
|
679
|
+
@content_nested[content_key] += content
|
|
680
|
+
end
|
|
681
|
+
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
end
|
|
685
|
+
|
|
686
|
+
# Writes the Base Service -> IE: SkyButlerService.
|
|
687
|
+
# @return void
|
|
688
|
+
def write_base
|
|
689
|
+
|
|
690
|
+
class_name = "#{@site_name_camel_cased}SDK"
|
|
691
|
+
|
|
692
|
+
contents = @template_base
|
|
693
|
+
contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, 'base', SERVICE_INTERNAL))
|
|
694
|
+
contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
|
|
695
|
+
contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
|
|
696
|
+
contents = contents.gsub(PLACEHOLDER_SITE_NAME_CAMEL_CASED, @site_name_camel_cased)
|
|
697
|
+
contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
|
|
698
|
+
|
|
699
|
+
service_names = []
|
|
700
|
+
service_getters = ''
|
|
701
|
+
|
|
702
|
+
@schema_resources.each do |data|
|
|
703
|
+
|
|
704
|
+
# This filters out the "mock" schema used for testing.
|
|
705
|
+
next if data[0].split('.')[0] == Blufin::YmlSchemaValidator::MOCK
|
|
706
|
+
|
|
707
|
+
data = data[1]
|
|
708
|
+
service_name = Blufin::Strings::snake_case_to_camel_case(data[:table])
|
|
709
|
+
service_getters += @template_service_getter.gsub(PLACEHOLDER_SERVICE, service_name)
|
|
710
|
+
|
|
711
|
+
# Technically this will never be reached, but if it does we know there's and issue where we have a service name conflict that needs to be validated for.
|
|
712
|
+
# A conflict could be: app.sale_ebay.inventory AND common.sale.ebay_inventory.
|
|
713
|
+
# This will probably never happen though so I won't waste time now (10/6/16) writing validation for this.
|
|
714
|
+
raise RuntimeError, "Duplicated service name: #{service_name}" if service_names.include?(service_name)
|
|
715
|
+
|
|
716
|
+
service_names << service_name
|
|
717
|
+
end
|
|
718
|
+
|
|
719
|
+
base_import_schemas = ''
|
|
720
|
+
base_import_schemas += "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.sdk.service.*;\n" if @base_import_schemas.any?
|
|
721
|
+
|
|
722
|
+
contents = contents.gsub(PLACEHOLDER_BASE_IMPORT, base_import_schemas)
|
|
723
|
+
contents = contents.gsub(PLACEHOLDER_SERVICE_GETTERS, service_getters)
|
|
724
|
+
contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
|
|
725
|
+
|
|
726
|
+
write_file_java("#{@path_base}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents))
|
|
727
|
+
|
|
728
|
+
end
|
|
729
|
+
|
|
730
|
+
end
|
|
731
|
+
|
|
732
|
+
end
|