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.
Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/bin/bf +5 -0
  3. data/bin/blufin +5 -0
  4. data/lib/blufin.rb +245 -0
  5. data/lib/core/code_scanners/common/scanner_common.rb +83 -0
  6. data/lib/core/code_scanners/common/scanner_java.rb +106 -0
  7. data/lib/core/code_scanners/scanner_java_embedded_objects.rb +386 -0
  8. data/lib/core/code_scanners/scanner_java_enums.rb +125 -0
  9. data/lib/core/code_scanners/scanner_java_source.rb +29 -0
  10. data/lib/core/code_scanners/scanner_java_tests.rb +157 -0
  11. data/lib/core/error_handling/schema_error.rb +9 -0
  12. data/lib/core/error_handling/sql_error.rb +21 -0
  13. data/lib/core/error_handling/sql_error_handler.rb +149 -0
  14. data/lib/core/error_handling/yml_error.rb +21 -0
  15. data/lib/core/error_handling/yml_error_handler.rb +437 -0
  16. data/lib/core/mysql.rb +347 -0
  17. data/lib/core/opt.rb +21 -0
  18. data/lib/core/site/site.rb +26 -0
  19. data/lib/core/site/site_auth.rb +88 -0
  20. data/lib/core/site/site_embedded.rb +27 -0
  21. data/lib/core/site/site_ports.rb +9 -0
  22. data/lib/core/site/site_resolver.rb +276 -0
  23. data/lib/core/site/site_services.rb +162 -0
  24. data/lib/core/site/site_ui.rb +16 -0
  25. data/lib/core/yml/config/yml_config_validator.rb +219 -0
  26. data/lib/core/yml/maven/yml_maven_validator.rb +1132 -0
  27. data/lib/core/yml/resource/yml_resource_validator.rb +154 -0
  28. data/lib/core/yml/schema/yml_schema_flags.rb +9 -0
  29. data/lib/core/yml/schema/yml_schema_validator.rb +1850 -0
  30. data/lib/core/yml/yml_cache_handler.rb +115 -0
  31. data/lib/core/yml/yml_common.rb +487 -0
  32. data/lib/core/yml/yml_meta_writer_base.rb +300 -0
  33. data/lib/core/yml/yml_outputter.rb +307 -0
  34. data/lib/core/yml/yml_validator_base.rb +630 -0
  35. data/lib/core/yml_writers/yml_configuration_writer.rb +40 -0
  36. data/lib/core/yml_writers/yml_java_api_resource_writer.rb +348 -0
  37. data/lib/core/yml_writers/yml_java_cron_type_writer.rb +113 -0
  38. data/lib/core/yml_writers/yml_java_css_dependency_writer.rb +59 -0
  39. data/lib/core/yml_writers/yml_java_dao_writer.rb +364 -0
  40. data/lib/core/yml_writers/yml_java_dto_writer.rb +251 -0
  41. data/lib/core/yml_writers/yml_java_embedded_object_writer.rb +968 -0
  42. data/lib/core/yml_writers/yml_java_enum_writer.rb +161 -0
  43. data/lib/core/yml_writers/yml_java_js_dependency_writer.rb +59 -0
  44. data/lib/core/yml_writers/yml_java_message_type_writer.rb +106 -0
  45. data/lib/core/yml_writers/yml_java_meta_writer.rb +173 -0
  46. data/lib/core/yml_writers/yml_java_model_writer.rb +510 -0
  47. data/lib/core/yml_writers/yml_java_pom_writer.rb +1050 -0
  48. data/lib/core/yml_writers/yml_java_resource_data_writer.rb +251 -0
  49. data/lib/core/yml_writers/yml_java_sdk_writer.rb +732 -0
  50. data/lib/core/yml_writers/yml_java_validator_writer.rb +280 -0
  51. data/lib/core/yml_writers/yml_java_worker_writer.rb +81 -0
  52. data/lib/core/yml_writers/yml_sql_structure_writer.rb +307 -0
  53. data/lib/core/yml_writers/yml_sql_template_writer.rb +243 -0
  54. data/lib/core/yml_writers/yml_vue_service_writer.rb +170 -0
  55. data/lib/core/yml_writers/yml_writer_base.rb +114 -0
  56. data/lib/routes/api_list.rb +35 -0
  57. data/lib/routes/api_meta.rb +59 -0
  58. data/lib/routes/build.rb +46 -0
  59. data/lib/routes/create/create_api.rb +35 -0
  60. data/lib/routes/create/create_ui.rb +84 -0
  61. data/lib/routes/export.rb +56 -0
  62. data/lib/routes/generate/generate_api.rb +225 -0
  63. data/lib/routes/generate/generate_img_favicon.rb +56 -0
  64. data/lib/routes/generate/generate_img_landing.rb +94 -0
  65. data/lib/routes/generate/generate_lambda.rb +43 -0
  66. data/lib/routes/lint.rb +35 -0
  67. data/lib/routes/mysql_reset.rb +43 -0
  68. data/lib/routes/release_blufin.rb +351 -0
  69. data/lib/routes/run.rb +35 -0
  70. data/lib/version.rb +1 -0
  71. data/opt/README.MD +2 -0
  72. data/opt/config/schema.yml +73 -0
  73. data/opt/config/template.yml +25 -0
  74. data/opt/sql/data/config/data-client.sql +7 -0
  75. data/opt/sql/data/config/data-db-configuration-property.sql +47 -0
  76. data/opt/sql/data/config/data-db-configuration.sql +9 -0
  77. data/opt/sql/data/config/data-db.sql +175 -0
  78. data/opt/sql/data/config/data-profile-api.sql +47 -0
  79. data/opt/sql/data/config/data-profile-cron.sql +0 -0
  80. data/opt/sql/data/config/data-profile-worker.sql +0 -0
  81. data/opt/sql/data/config/data-profile.sql +87 -0
  82. data/opt/sql/data/config/data-project.sql +95 -0
  83. data/opt/sql/structure/blufin-master-structure-fks.sql +65 -0
  84. data/opt/sql/structure/blufin-master-structure.sql +97 -0
  85. data/opt/sql/structure/blufin-mock-structure-fks.sql +38 -0
  86. data/opt/sql/structure/blufin-mock-structure.sql +98 -0
  87. data/opt/sql/templates/config/template-client.sql +7 -0
  88. data/opt/sql/templates/config/template-db-configuration-property.sql +11 -0
  89. data/opt/sql/templates/config/template-db-configuration.sql +9 -0
  90. data/opt/sql/templates/config/template-db.sql +21 -0
  91. data/opt/sql/templates/config/template-profile-api.sql +11 -0
  92. data/opt/sql/templates/config/template-profile-cron.sql +7 -0
  93. data/opt/sql/templates/config/template-profile-worker.sql +7 -0
  94. data/opt/sql/templates/config/template-profile.sql +21 -0
  95. data/opt/sql/templates/config/template-project.sql +23 -0
  96. data/opt/yml/api/schema/config/client.yml +14 -0
  97. data/opt/yml/api/schema/config/db.yml +45 -0
  98. data/opt/yml/api/schema/config/db_configuration.yml +22 -0
  99. data/opt/yml/api/schema/config/db_configuration_property.yml +22 -0
  100. data/opt/yml/api/schema/config/profile.yml +53 -0
  101. data/opt/yml/api/schema/config/profile_api.yml +22 -0
  102. data/opt/yml/api/schema/config/profile_cron.yml +14 -0
  103. data/opt/yml/api/schema/config/profile_worker.yml +14 -0
  104. data/opt/yml/api/schema/config/project.yml +48 -0
  105. data/opt/yml/api/schema/mock/mock.yml +99 -0
  106. data/opt/yml/api/schema/mock/mock_nested_if_enum.yml +16 -0
  107. data/opt/yml/api/schema/mock/mock_nested_if_enum_system.yml +16 -0
  108. data/opt/yml/api/schema/mock/mock_nested_linked.yml +43 -0
  109. data/opt/yml/api/schema/mock/mock_nested_multiple.yml +61 -0
  110. data/opt/yml/api/schema/mock/mock_nested_single.yml +67 -0
  111. data/opt/yml/api/schema/mock/mock_nested_single_super_deep.yml +32 -0
  112. data/opt/yml/api/schema/mock/mock_nested_single_super_super_deep.yml +17 -0
  113. metadata +240 -0
@@ -0,0 +1,510 @@
1
+ module Blufin
2
+
3
+ class YmlJavaModelWriter < Blufin::YmlWriterBase
4
+
5
+ SERVICE = Blufin::SiteServices::API
6
+ PACKAGE = "#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.model"
7
+
8
+ PLACEHOLDER_SITE_NAME = '{{--SITE-NAME--}}'
9
+ PLACEHOLDER_SITE_DOMAIN = '{{--SITE-DOMAIN--}}'
10
+ PLACEHOLDER_OBJECT = '{{--OBJECT--}}'
11
+ PLACEHOLDER_OBJECT_LOWER = '{{--OBJECT-LOWER--}}'
12
+ PLACEHOLDER_CLASS_PROPERTIES = '{{--CLASS-PROPERTIES--}}'
13
+ PLACEHOLDER_CONSTRUCTOR_CONTENT = '{{--CONSTRUCTOR-CONTENT--}}'
14
+ PLACEHOLDER_IMPORT = '{{--IMPORT--}}'
15
+ PLACEHOLDER_RESOURCE_DEPTHS = '{{--RESOURCE-DEPTHS--}}'
16
+ PLACEHOLDER_GET = '{{--DEPENDENT-GET--}}'
17
+ PLACEHOLDER_GET_CALLS = '{{--DEPENDENT-GET-CALLS--}}'
18
+ PLACEHOLDER_POST_ID_CAPTURE = '{{--DEPENDENT-POST-ID-CAPTURE--}}'
19
+ PLACEHOLDER_POST_INITIAL = '{{--DEPENDENT-POST-INITIAL--}}'
20
+ PLACEHOLDER_POST = '{{--DEPENDENT-POST--}}'
21
+ PLACEHOLDER_PUT = '{{--DEPENDENT-PUT--}}'
22
+ PLACEHOLDER_PUT_INITIAL = '{{--DEPENDENT-PUT-INITIAL--}}'
23
+ PLACEHOLDER_PUT_ORPHAN_REMOVAL = '{{--DEPENDENT-PUT-ORPHAN-REMOVAL--}}'
24
+ PLACEHOLDER_PATCH = '{{--DEPENDENT-PATCH--}}'
25
+ PLACEHOLDER_DELETE = '{{--DEPENDENT-DELETE--}}'
26
+ PLACEHOLDER_SCHEMA_UPPERCASE = '{{--PLACEHOLDER-SCHEMA-UPPERCASE}--}'
27
+ PLACEHOLDER_CONTENT = '{{--CONTENT--}}'
28
+
29
+ # @return void
30
+ def initialize(site, schema_data, schema_resources)
31
+
32
+ @schema_data = schema_data
33
+ @schema_resources = schema_resources
34
+
35
+ raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
36
+ raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash)
37
+
38
+ @site = Blufin::SiteResolver::validate_site(site)
39
+ @site_name = Blufin::SiteResolver::get_site_name(@site)
40
+ @site_domain = Blufin::SiteResolver::get_site_domain(@site)
41
+ @site_domain_gsub = @site_domain.strip == '' ? '' : "#{@site_domain}"
42
+ @site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
43
+
44
+ # Wipe out all previous files.
45
+ Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
46
+ path_to_wipe_out = "#{get_java_path(@site, schema, SERVICE, PACKAGE)}"
47
+ if Blufin::Files::path_exists(path_to_wipe_out)
48
+ if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
49
+ Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
50
+ end
51
+ end
52
+ end
53
+
54
+ @template = <<TEMPLATE
55
+ package #{PLACEHOLDER_SITE_DOMAIN}.#{PLACEHOLDER_SITE_NAME}.api.#{PACKAGE};
56
+
57
+ import org.blufin.api.base.AbstractResource;
58
+ import org.blufin.base.enums.SchemaType;
59
+ import org.blufin.api.base.AbstractModel;
60
+ import org.blufin.base.exceptions.BlufinServerException;
61
+ import org.blufin.base.exceptions.BlufinClientException;
62
+ import org.blufin.base.exceptions.BlufinNotImplementedException;
63
+ import org.blufin.base.helper.IdSet;
64
+ import lombok.Getter;
65
+ import org.blufin.api.base.model.GetModel;
66
+ import org.blufin.api.base.model.PostModel;
67
+ import org.blufin.api.base.model.PutModel;
68
+ import org.blufin.api.base.model.PatchModel;
69
+ import org.blufin.api.base.model.DeleteModel;
70
+ import org.blufin.base.helper.Pair;
71
+ import org.blufin.core.server.db.ConnectionFactory;
72
+ import org.blufin.sdk.response.ApiResponsePagination;
73
+ import org.blufin.api.helper.IdExtractor;
74
+ import org.blufin.base.helper.IdSet;
75
+ import org.blufin.sdk.rest.GetRequest;
76
+ import org.blufin.sdk.rest.PostRequest;
77
+ import org.blufin.sdk.rest.PutRequest;
78
+ import org.blufin.sdk.rest.PatchRequest;
79
+ import org.blufin.sdk.rest.DeleteRequest;
80
+ import org.blufin.sdk.response.ApiResponse;
81
+ import org.blufin.sdk.response.ResourceModificationResponse;
82
+ import org.blufin.sdk.base.PersistentDto;
83
+ import #{PLACEHOLDER_SITE_DOMAIN}.#{PLACEHOLDER_SITE_NAME}.api.#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.dao.#{PLACEHOLDER_OBJECT}Dao;
84
+ import #{PLACEHOLDER_SITE_DOMAIN}.#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{PLACEHOLDER_OBJECT};
85
+ import java.sql.Connection;
86
+ import java.util.concurrent.ExecutionException;
87
+ import java.util.concurrent.ExecutorService;
88
+ import java.util.concurrent.Executors;
89
+ import org.apache.commons.dbutils.DbUtils;
90
+ import java.util.HashSet;
91
+ import java.util.Set;
92
+ import java.util.List;
93
+ import java.sql.Connection;
94
+ import java.sql.SQLException;
95
+ import org.springframework.stereotype.Service;
96
+ import java.util.Map;#{PLACEHOLDER_IMPORT}
97
+
98
+ @Service
99
+ public final class #{PLACEHOLDER_OBJECT}Model extends AbstractModel<#{PLACEHOLDER_OBJECT}> {
100
+
101
+ @Getter
102
+ private static final #{PLACEHOLDER_OBJECT}Model instance = new #{PLACEHOLDER_OBJECT}Model();
103
+
104
+ #{PLACEHOLDER_CLASS_PROPERTIES}
105
+
106
+ private #{PLACEHOLDER_OBJECT}Model() {
107
+
108
+ #{PLACEHOLDER_CONSTRUCTOR_CONTENT}
109
+ }
110
+ #{PLACEHOLDER_CONTENT}}
111
+ TEMPLATE
112
+
113
+ @template_get = <<TEMPLATE
114
+
115
+ @Override
116
+ protected ApiResponse<#{PLACEHOLDER_OBJECT}> get(Connection connection, GetRequest request) throws BlufinServerException {
117
+
118
+ Pair<ApiResponsePagination, List<#{PLACEHOLDER_OBJECT}>> #{PLACEHOLDER_OBJECT_LOWER}Response = #{PLACEHOLDER_OBJECT_LOWER}Dao.get(connection, request);
119
+ #{PLACEHOLDER_GET}
120
+ return buildApiResponse(#{PLACEHOLDER_OBJECT_LOWER}Response.getKey(), #{PLACEHOLDER_OBJECT_LOWER}Response.getValue());
121
+ }
122
+ TEMPLATE
123
+
124
+ @template_post = <<TEMPLATE
125
+
126
+ @Override
127
+ protected void post(Connection connection, PostRequest<#{PLACEHOLDER_OBJECT}> request) throws BlufinServerException {
128
+
129
+ #{PLACEHOLDER_POST_ID_CAPTURE}for (#{PLACEHOLDER_OBJECT} #{PLACEHOLDER_OBJECT_LOWER} : request.getPayload()) {
130
+
131
+ #{PLACEHOLDER_POST_INITIAL}#{PLACEHOLDER_POST} }
132
+ }
133
+ TEMPLATE
134
+
135
+ @template_put = <<TEMPLATE
136
+
137
+ @Override
138
+ protected void put(Connection connection, PutRequest<#{PLACEHOLDER_OBJECT}> request) throws BlufinServerException {
139
+
140
+ #{PLACEHOLDER_PUT_ORPHAN_REMOVAL}for (#{PLACEHOLDER_OBJECT} #{PLACEHOLDER_OBJECT_LOWER} : request.getPayload()) {
141
+
142
+ #{PLACEHOLDER_PUT_INITIAL}#{PLACEHOLDER_PUT} }
143
+ }
144
+ TEMPLATE
145
+
146
+ @template_patch = <<TEMPLATE
147
+
148
+ @Override
149
+ protected void patch(Connection connection, PatchRequest request) throws BlufinServerException {
150
+
151
+ #{PLACEHOLDER_PATCH}
152
+ }
153
+ TEMPLATE
154
+
155
+ @template_delete = <<TEMPLATE
156
+
157
+ @Override
158
+ protected void delete(Connection connection, DeleteRequest request) throws BlufinServerException {
159
+
160
+ #{PLACEHOLDER_DELETE}
161
+ }
162
+ TEMPLATE
163
+
164
+ @template_get_blank = <<TEMPLATE
165
+
166
+ @Override
167
+ protected ApiResponse<#{PLACEHOLDER_OBJECT}> get(Connection connection, GetRequest request) throws BlufinServerException {
168
+
169
+ throw new BlufinNotImplementedException();
170
+ }
171
+ TEMPLATE
172
+
173
+ @template_post_blank = <<TEMPLATE
174
+
175
+ @Override
176
+ protected void post(Connection connection, PostRequest<#{PLACEHOLDER_OBJECT}> request) throws BlufinServerException {
177
+
178
+ throw new BlufinNotImplementedException();
179
+ }
180
+ TEMPLATE
181
+
182
+ @template_put_blank = <<TEMPLATE
183
+
184
+ @Override
185
+ protected void put(Connection connection, PutRequest<#{PLACEHOLDER_OBJECT}> request) throws BlufinServerException {
186
+
187
+ throw new BlufinNotImplementedException();
188
+ }
189
+ TEMPLATE
190
+
191
+ @template_patch_blank = <<TEMPLATE
192
+
193
+ @Override
194
+ protected void patch(Connection connection, PatchRequest request) throws BlufinServerException {
195
+
196
+ throw new BlufinNotImplementedException();
197
+ }
198
+ TEMPLATE
199
+
200
+ @template_delete_blank = <<TEMPLATE
201
+
202
+ @Override
203
+ protected void delete(Connection connection, DeleteRequest request) throws BlufinServerException {
204
+
205
+ throw new BlufinNotImplementedException();
206
+ }
207
+ TEMPLATE
208
+
209
+ end
210
+
211
+ # @return void
212
+ def write
213
+
214
+ @schema_data.each do |schema, schema_data|
215
+
216
+ schema_data.keys.each do |table|
217
+
218
+ object = Blufin::Strings::snake_case_to_camel_case(table)
219
+ object_lower = Blufin::Strings::snake_case_to_camel_case_lower(table)
220
+
221
+ resource_data = @schema_resources["#{schema}.#{table}"]
222
+
223
+ @has_get = YmlCommon::has_http_method(Blufin::YmlConfigValidator::GET, resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL)
224
+ @has_post = YmlCommon::has_http_method(Blufin::YmlConfigValidator::POST, resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL)
225
+ @has_put = YmlCommon::has_http_method(Blufin::YmlConfigValidator::PUT, resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL)
226
+ @has_patch = YmlCommon::has_http_method(Blufin::YmlConfigValidator::PATCH, resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL)
227
+ @has_delete = YmlCommon::has_http_method(Blufin::YmlConfigValidator::DELETE, resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL)
228
+
229
+ # Skip if this resource has no HTTP Methods.
230
+ next unless Blufin::YmlCommon::has_at_least_one_http_method(resource_data, Blufin::YmlSchemaValidator::CONFIG_INTERNAL)
231
+
232
+ @import_statements = []
233
+ @daos = [table]
234
+ @contents_get = []
235
+ @contents_get_calls = ''
236
+ @contents_post = []
237
+ @contents_put = []
238
+ @contents_patch = []
239
+ @contents_delete = []
240
+
241
+ contents = @template
242
+ contents_inner = ''
243
+ contents_inner += @has_get ? @template_get : @template_get_blank
244
+ contents_inner += @has_post ? @template_post : @template_post_blank
245
+ contents_inner += @has_put ? @template_put : @template_put_blank
246
+ contents_inner += @has_patch ? @template_patch : @template_patch_blank
247
+ contents_inner += @has_delete ? @template_delete : @template_delete_blank
248
+
249
+ # # TODO - REMOVE (Once POST/PUT/DELETE fully working)
250
+ # if "#{schema}.#{table}" == 'mock.mock_nested_multiple' || "#{schema}.#{table}" == 'app.root_multiple'
251
+ #
252
+ # # TODO - REMOVE (Once POST/PUT/DELETE fully working)
253
+ # puts "\x1B[38;5;198m#{schema}.#{table}\x1B[0m"
254
+ # puts resource_data.to_yaml
255
+
256
+ @contents_patch << " #{PLACEHOLDER_OBJECT_LOWER}Dao.patch(connection, request.getPayLoad());" if @has_patch
257
+ @contents_delete << " #{PLACEHOLDER_OBJECT_LOWER}Dao.delete(connection, request.getIds());" if @has_delete
258
+
259
+ @has_children = false
260
+ @parent = resource_data[:parent]
261
+ @child_type = Blufin::YmlCommon::extract_child_type_from_schema_data(@schema_data, schema, table)
262
+ @child_type_java = Blufin::YmlCommon::extract_child_type_from_schema_data_for_java(@schema_data, schema, table)
263
+
264
+ if !resource_data[:dependents].nil? && resource_data[:dependents].any?
265
+
266
+ @objects = {}
267
+ @has_children = true
268
+
269
+ resource_data[:dependents].each do |dependent|
270
+ dependent_data = @schema_resources["#{schema}.#{dependent}"]
271
+ depth = dependent_data[:depth] - @schema_resources["#{schema}.#{table}"][:depth]
272
+ parent_object = dependent_data[:tree][dependent_data[:tree].length - 2]
273
+ dependent_data[:depth_relative] = depth
274
+ @objects[parent_object] = [] unless @objects[parent_object].is_a?(Array)
275
+ @objects[parent_object] << dependent_data
276
+ end
277
+
278
+ if @has_get
279
+
280
+ @contents_get << ''
281
+ @contents_get << " if (#{PLACEHOLDER_OBJECT_LOWER}Response.getValue().size() > 0) {"
282
+ @contents_get << ''
283
+ @contents_get << " List<Integer> #{PLACEHOLDER_OBJECT_LOWER}Ids = IdExtractor.extractIds(#{PLACEHOLDER_OBJECT_LOWER}Response.getValue());"
284
+ @contents_get << ''
285
+ @contents_get << PLACEHOLDER_GET_CALLS
286
+ @contents_get << ''
287
+ @contents_get << ' DbUtils.closeQuietly(connection);'
288
+ @contents_get << ''
289
+ @contents_get << " for (#{PLACEHOLDER_OBJECT} #{PLACEHOLDER_OBJECT_LOWER} : #{PLACEHOLDER_OBJECT_LOWER}Response.getValue()) {"
290
+
291
+ loop_tree(table)
292
+
293
+ @contents_get << ' }'
294
+ @contents_get << ' }'
295
+ @contents_get << ''
296
+
297
+ end
298
+
299
+ # Add trailing new line(s) for code-formatting purposes.
300
+ @contents_post[@contents_post.length - 1] += "\n" if @contents_post.any? && @has_post
301
+ if @contents_put.any? && @has_put
302
+ @contents_put.unshift('')
303
+ @contents_put[@contents_put.length - 1] += "\n"
304
+ end
305
+
306
+ end
307
+
308
+ # end # TODO - REMOVE
309
+
310
+ post_id_capture = ''
311
+
312
+ if @child_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT
313
+ post_initial = " int #{object_lower}Id = #{object_lower}Dao.post(connection, #{object_lower});\n\n request.addIdToResponse(#{object_lower}Id);\n"
314
+ put_initial = " putObjectElement(connection, #{PLACEHOLDER_OBJECT_LOWER}, #{PLACEHOLDER_OBJECT_LOWER}.getParentId(), #{PLACEHOLDER_OBJECT_LOWER}Dao);\n\n request.addIdToResponse(#{PLACEHOLDER_OBJECT_LOWER}.getId());\n"
315
+ elsif @child_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST
316
+ post_id_capture = "request.addParentDataToResponse(request.getPayload(), \"#{table}\", \"#{@parent}_id\");\n\n "
317
+ post_initial = " int #{object_lower}Id = #{object_lower}Dao.post(connection, #{object_lower});\n"
318
+ put_initial = " #{PLACEHOLDER_OBJECT_LOWER}.setId(putListElement(connection, #{PLACEHOLDER_OBJECT_LOWER}, #{PLACEHOLDER_OBJECT_LOWER}Dao));\n\n request.addIdToResponse(#{PLACEHOLDER_OBJECT_LOWER}.getId());\n"
319
+ else
320
+ post_initial = " int #{object_lower}Id = #{object_lower}Dao.post(connection, #{object_lower});\n\n request.addIdToResponse(#{object_lower}Id);\n"
321
+ put_initial = " putObjectElement(connection, #{PLACEHOLDER_OBJECT_LOWER}, #{PLACEHOLDER_OBJECT_LOWER}Dao);\n\n request.addIdToResponse(#{PLACEHOLDER_OBJECT_LOWER}.getId());\n"
322
+ end
323
+
324
+ put_orphan_removal = @child_type_java.nil? || @child_type != Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST ? '' : "removeOrphans(connection, request.getPayload(), #{object_lower}Dao);\n\n "
325
+
326
+ contents_inner = contents_inner.gsub(PLACEHOLDER_GET, Blufin::YmlCommon::convert_line_array_to_string(@contents_get))
327
+ contents_inner = contents_inner.gsub(PLACEHOLDER_POST_ID_CAPTURE, post_id_capture)
328
+ contents_inner = contents_inner.gsub(PLACEHOLDER_POST_INITIAL, post_initial)
329
+ contents_inner = contents_inner.gsub(PLACEHOLDER_POST, Blufin::YmlCommon::convert_line_array_to_string(@contents_post))
330
+ contents_inner = contents_inner.gsub(PLACEHOLDER_PUT, Blufin::YmlCommon::convert_line_array_to_string(@contents_put))
331
+ contents_inner = contents_inner.gsub(PLACEHOLDER_PUT_INITIAL, put_initial)
332
+ contents_inner = contents_inner.gsub(PLACEHOLDER_PUT_ORPHAN_REMOVAL, put_orphan_removal)
333
+ contents_inner = contents_inner.gsub(PLACEHOLDER_PATCH, Blufin::YmlCommon::convert_line_array_to_string(@contents_patch))
334
+ contents_inner = contents_inner.gsub(PLACEHOLDER_DELETE, Blufin::YmlCommon::convert_line_array_to_string(@contents_delete))
335
+
336
+ @import_statements.sort!
337
+ @import_statements.uniq!
338
+
339
+ contents = contents.gsub(PLACEHOLDER_CONTENT, contents_inner.to_s)
340
+ contents = contents.gsub(PLACEHOLDER_CLASS_PROPERTIES, Blufin::YmlCommon::convert_line_array_to_string(get_class_properties))
341
+ contents = contents.gsub(PLACEHOLDER_CONSTRUCTOR_CONTENT, Blufin::YmlCommon::convert_line_array_to_string(get_constructor_content))
342
+ contents = contents.gsub(PLACEHOLDER_GET_CALLS, @contents_get_calls)
343
+
344
+ contents = contents.gsub(PLACEHOLDER_IMPORT, @import_statements.any? ? "\n#{@import_statements.join("\n")}" : '')
345
+ contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
346
+ contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
347
+ contents = contents.gsub(PLACEHOLDER_SCHEMA, schema)
348
+ contents = contents.gsub(PLACEHOLDER_SCHEMA_UPPERCASE, schema.upcase)
349
+ contents = contents.gsub(PLACEHOLDER_OBJECT, object)
350
+ contents = contents.gsub(PLACEHOLDER_OBJECT_LOWER, object_lower)
351
+
352
+ # Hacky-fix for test classes. DO NOT remove this or Java won't compile.
353
+ contents = contents.gsub('SchemaType.MOCK', 'null') if schema == Blufin::YmlSchemaValidator::MOCK
354
+
355
+ write_file_java("#{get_java_path(@site, schema, SERVICE, PACKAGE)}/#{object}Model.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
356
+
357
+ end
358
+
359
+ end
360
+
361
+ end
362
+
363
+ private
364
+
365
+ def loop_tree(parent)
366
+
367
+ if @objects.has_key?(parent)
368
+
369
+ @objects[parent].each_with_index do |object, idx|
370
+
371
+ obj_schema = object[:schema]
372
+ obj_table = object[:table]
373
+ obj_type = object[:type]
374
+ # obj_tree = object[:tree] # TODO - REMOVE ONCE DONE (IF NOT NEEDED)
375
+ obj_depth = object[:depth_relative]
376
+ obj_cc = Blufin::Strings::snake_case_to_camel_case(obj_table)
377
+ obj_ccl = Blufin::Strings::snake_case_to_camel_case_lower(obj_table)
378
+ # parent_cc = Blufin::Strings::snake_case_to_camel_case(parent) # TODO - REMOVE ONCE DONE (IF NOT NEEDED)
379
+ parent_ccl = Blufin::Strings::snake_case_to_camel_case_lower(parent)
380
+ closing_get = []
381
+ closing_post = []
382
+ closing_put = []
383
+ closing_delete = []
384
+
385
+ previous_was_list = @schema_resources["#{obj_schema}.#{parent}"][:type] == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST
386
+ has_children = @objects.has_key?(obj_table)
387
+
388
+ a = "#{@child_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST ? ' ' : ' '}#{' ' * obj_depth}"
389
+ a = previous_was_list ? "#{a} " : a
390
+
391
+ b = "#{@child_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST ? ' ' : ' '}#{' ' * obj_depth}"
392
+ b = previous_was_list ? "#{b} " : b
393
+
394
+ @daos << obj_table unless @daos.include?(obj_table)
395
+ @import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}.#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{obj_cc};"
396
+ @import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}.#{PLACEHOLDER_SITE_NAME}.api.#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.dao.#{obj_cc}Dao;"
397
+
398
+ map_ids_method = "IdExtractor.extractIds#{previous_was_list ? 'FromList' : ''}"
399
+ map_ids_string = obj_depth == 1 ? "#{PLACEHOLDER_OBJECT_LOWER}Ids" : "#{map_ids_method}(#{parent_ccl}Result)"
400
+
401
+ case obj_type
402
+ when Blufin::ScannerJavaEmbeddedObjects::OBJECT
403
+
404
+ if @has_get
405
+ @contents_get_calls << " Map<Integer, #{obj_cc}> #{obj_ccl}Result = #{obj_ccl}Dao.getObject(connection, \"#{parent}_id\", #{map_ids_string});\n"
406
+ @contents_get << ''
407
+ @contents_get << "#{a}#{obj_cc} #{obj_ccl} = #{obj_ccl}Result.get(#{parent_ccl}.getId());"
408
+ @contents_get << ''
409
+ @contents_get << "#{a}if (#{obj_ccl} != null) {"
410
+ @contents_get << ''
411
+ @contents_get << " #{a}#{parent_ccl}.set#{obj_cc}(#{obj_ccl});"
412
+ closing_get << "#{a}}"
413
+ end
414
+
415
+ if @has_post
416
+ @contents_post << ''
417
+ @contents_post << "#{b}if (#{parent_ccl}.get#{obj_cc}() != null) {"
418
+ @contents_post << ''
419
+ @contents_post << " #{b}#{obj_cc} #{obj_ccl} = #{parent_ccl}.get#{obj_cc}();"
420
+ @contents_post << ''
421
+ @contents_post << " #{b}#{has_children ? "int #{obj_ccl}Id = " : ''}#{obj_ccl}Dao.post(connection, #{obj_ccl}, #{parent_ccl}Id);"
422
+ closing_post << "#{b}}"
423
+ end
424
+
425
+ if @has_put
426
+ @contents_put << ''
427
+ @contents_put << "#{b}if (#{parent_ccl}.get#{obj_cc}() != null) {"
428
+ @contents_put << ''
429
+ @contents_put << " #{b}#{obj_cc} #{obj_ccl} = #{parent_ccl}.get#{obj_cc}();"
430
+ @contents_put << ''
431
+ @contents_put << " #{b}putObjectElement(connection, #{obj_ccl}, #{parent_ccl}.getId(), #{obj_ccl}Dao);"
432
+ closing_put << "#{b}}"
433
+ end
434
+
435
+ when Blufin::ScannerJavaEmbeddedObjects::OBJECT_LIST
436
+
437
+ if @has_get
438
+ @contents_get_calls << " Map<Integer, List<#{obj_cc}>> #{obj_ccl}Result = #{obj_ccl}Dao.getObjectList(connection, \"#{parent}_id\", #{map_ids_string});\n"
439
+ @contents_get << ''
440
+ @contents_get << "#{a}List<#{obj_cc}> #{obj_ccl}List = #{obj_ccl}Result.get(#{parent_ccl}.getId());"
441
+ @contents_get << ''
442
+ @contents_get << "#{a}if (#{obj_ccl}List != null && #{obj_ccl}List.size() > 0) {"
443
+ @contents_get << ''
444
+ @contents_get << " #{a}for (#{obj_cc} #{obj_ccl} : #{obj_ccl}List) {"
445
+ @contents_get << ''
446
+ @contents_get << " #{a}#{parent_ccl}.get#{obj_cc}List().add(#{obj_ccl});"
447
+ closing_get << " #{a}}"
448
+ closing_get << "#{a}}"
449
+ end
450
+
451
+ if @has_post
452
+ @contents_post << ''
453
+ @contents_post << "#{b}if (#{parent_ccl}.get#{obj_cc}List() != null && #{parent_ccl}.get#{obj_cc}List().size() > 0) {"
454
+ @contents_post << ''
455
+ @contents_post << " #{b}for (#{obj_cc} #{obj_ccl} : #{parent_ccl}.get#{obj_cc}List()) {"
456
+ @contents_post << ''
457
+ @contents_post << " #{b}#{has_children ? "int #{obj_ccl}Id = " : ''}#{obj_ccl}Dao.post(connection, #{obj_ccl}, #{parent_ccl}Id);"
458
+ closing_post << " #{b}}"
459
+ closing_post << "#{b}}"
460
+ end
461
+
462
+ if @has_put
463
+ @contents_put << ''
464
+ @contents_put << "#{b}removeOrphans(connection, #{parent_ccl}.get#{obj_cc}List(), #{parent_ccl}.getId(), #{obj_ccl}Dao);"
465
+ @contents_put << ''
466
+ @contents_put << "#{b}if (#{parent_ccl}.get#{obj_cc}List() != null && #{parent_ccl}.get#{obj_cc}List().size() > 0) {"
467
+ @contents_put << ''
468
+ @contents_put << " #{b}for (#{obj_cc} #{obj_ccl} : #{parent_ccl}.get#{obj_cc}List()) {"
469
+ @contents_put << ''
470
+ @contents_put << " #{b}#{obj_ccl}.setId(putListElement(connection, #{obj_ccl}, #{parent_ccl}.getId(), #{obj_ccl}Dao));"
471
+ closing_put << " #{b}}"
472
+ closing_put << "#{b}}"
473
+ end
474
+
475
+ when Blufin::ScannerJavaEmbeddedObjects::OBJECT_LINK
476
+
477
+ # TODO - FINISH THIS
478
+
479
+ else
480
+ raise RuntimeError, "Unhandled object type: #{obj_type}"
481
+ end
482
+
483
+ loop_tree(obj_table) if @objects.has_key?(obj_table)
484
+
485
+ closing_get.each { |x| @contents_get << x } if closing_get.any? && @has_get
486
+ closing_post.each { |x| @contents_post << x } if closing_post.any? && @has_post
487
+ closing_put.each { |x| @contents_put << x } if closing_put.any? && @has_put
488
+ closing_delete.each { |x| @contents_delete << x } if closing_delete.any? && @has_delete
489
+
490
+ end
491
+
492
+ end
493
+
494
+ end
495
+
496
+ def get_class_properties
497
+ content = []
498
+ @daos.each { |dao| content << " private final #{Blufin::Strings::snake_case_to_camel_case(dao)}Dao #{Blufin::Strings::snake_case_to_camel_case_lower(dao)}Dao;" }
499
+ content
500
+ end
501
+
502
+ def get_constructor_content
503
+ content = []
504
+ @daos.each { |dao| content << " this.#{Blufin::Strings::snake_case_to_camel_case_lower(dao)}Dao = #{Blufin::Strings::snake_case_to_camel_case(dao)}Dao.getInstance();" }
505
+ content
506
+ end
507
+
508
+ end
509
+
510
+ end