blufin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,300 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlMetaWriterBase < Blufin::YmlWriterBase
|
4
|
+
|
5
|
+
TYPE = 'TYPE'
|
6
|
+
MAX_LENGTH = 'MAX_LENGTH'
|
7
|
+
FLAG = 'FLAG'
|
8
|
+
FLAG_AUTO_INCREMENT = 'FLAG_AUTO_INCREMENT'
|
9
|
+
FLAG_INDEX = 'FLAG_INDEX'
|
10
|
+
FLAG_NULLABLE = 'FLAG_NULLABLE'
|
11
|
+
FLAG_PRIMARY_KEY = 'FLAG_PRIMARY_KEY'
|
12
|
+
FLAG_UNIQUE = 'FLAG_UNIQUE'
|
13
|
+
FKEY = 'FKEY'
|
14
|
+
LINK = 'LINK'
|
15
|
+
DESCRIPTION = 'DESCRIPTION'
|
16
|
+
REQUIRED = 'REQUIRED'
|
17
|
+
REQUIRED_IF = 'REQUIRED_IF'
|
18
|
+
ENCRYPTED = 'ENCRYPTED'
|
19
|
+
TRANSIENT = 'TRANSIENT'
|
20
|
+
CHILD_OF = 'CHILD_OF'
|
21
|
+
CURRENCY_CODE = 'CURRENCY_CODE'
|
22
|
+
DECIMAL_DISTRIBUTION = 'DECIMAL_DISTRIBUTION'
|
23
|
+
ENUM_NAME = 'ENUM_NAME'
|
24
|
+
ENUM_VALUES = 'ENUM_VALUES'
|
25
|
+
|
26
|
+
def handle_description(value)
|
27
|
+
@description = " put(#{DESCRIPTION}, \"#{value.gsub('"', '\"')}\");" if value != '' && !value.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def handle_type(value, schema, table, column_name, column_data)
|
31
|
+
|
32
|
+
converted_type = value
|
33
|
+
max_length = nil
|
34
|
+
|
35
|
+
if value == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
36
|
+
elsif Blufin::YmlSchemaValidator::DATETIME_TYPES.include?(value)
|
37
|
+
if value == Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT || value == Blufin::YmlSchemaValidator::TYPE_DATETIME_UPDATE
|
38
|
+
converted_type = 'DATETIME_INSERT' if value == Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT
|
39
|
+
converted_type = 'DATETIME_UPDATE' if value == Blufin::YmlSchemaValidator::TYPE_DATETIME_UPDATE
|
40
|
+
@transient = " put(#{TRANSIENT}, true);"
|
41
|
+
end
|
42
|
+
elsif value =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL
|
43
|
+
decimal_m, decimal_d = Blufin::YmlCommon::decimal_extract_values(value)
|
44
|
+
converted_type = 'DECIMAL' # DECIMAL(2,2) => "0.25" => length: 4 characters.
|
45
|
+
max_length = decimal_m + 1 + (decimal_m == decimal_d ? 1 : 0) # DECIMAL(4,2) => "42.25" => length: 5 characters.
|
46
|
+
@import_statements << 'import org.blufin.base.helper.Pair;'
|
47
|
+
@decimal_distribution = " put(#{DECIMAL_DISTRIBUTION}, Pair.of(#{decimal_m.to_i}, #{decimal_d.to_i}));"
|
48
|
+
elsif Blufin::YmlSchemaValidator::INT_TYPES.include?(value)
|
49
|
+
converted_type = 'INT_AUTO' if value == Blufin::YmlSchemaValidator::TYPE_INT_AUTO
|
50
|
+
elsif value == Blufin::YmlSchemaValidator::TYPE_INT_TINY
|
51
|
+
converted_type = 'INT_TINY'
|
52
|
+
elsif value == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
|
53
|
+
converted_type = 'INT_SMALL'
|
54
|
+
elsif value == Blufin::YmlSchemaValidator::TYPE_INT_BIG
|
55
|
+
converted_type = 'INT_BIG'
|
56
|
+
elsif Blufin::YmlSchemaValidator::TEXT_TYPES.include?(value)
|
57
|
+
# Do nothing.
|
58
|
+
elsif value =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
|
59
|
+
converted_type = 'VARCHAR'
|
60
|
+
max_length = Blufin::Strings::extract_using_regex(value, /\(\d+\)\z/, %w{( )})
|
61
|
+
elsif value =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
62
|
+
enum_values = Blufin::YmlCommon::enum_value_extractor(value, @site)
|
63
|
+
converted_type = 'ENUM'
|
64
|
+
max_length = enum_values.max_by(&:length).length
|
65
|
+
@import_statements << 'import java.util.Arrays;'
|
66
|
+
@enum_name = " put(#{ENUM_NAME}, \"#{Blufin::Strings::snake_case_to_camel_case(table)}#{Blufin::Strings::snake_case_to_camel_case(column_name)}\");"
|
67
|
+
@enum_values = " put(#{ENUM_VALUES}, Arrays.asList(\"#{enum_values.join('", "')}\"));"
|
68
|
+
elsif value =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM
|
69
|
+
custom_enum_name = Blufin::YmlCommon::enum_name_extractor(value)
|
70
|
+
enum_values = @yml_enum_scanner.get_enum_custom_values_for(custom_enum_name)
|
71
|
+
converted_type = 'ENUM_CUSTOM'
|
72
|
+
max_length = enum_values.max_by(&:length).length
|
73
|
+
@import_statements << "import #{get_package(@site, schema, 'enums', Blufin::SiteServices::SDK)}.#{custom_enum_name};"
|
74
|
+
@enum_name = " put(#{ENUM_NAME}, \"#{custom_enum_name}\");"
|
75
|
+
@enum_values = " put(#{ENUM_VALUES}, getEnumValues(#{custom_enum_name}.values()));"
|
76
|
+
elsif value =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
77
|
+
system_enum_name = Blufin::YmlCommon::enum_name_extractor(value)
|
78
|
+
enum_values = @yml_enum_scanner.get_enum_system_values_for(system_enum_name)
|
79
|
+
converted_type = 'ENUM_SYSTEM'
|
80
|
+
max_length = enum_values.max_by(&:length).length
|
81
|
+
@import_statements << "import #{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS}.#{system_enum_name};"
|
82
|
+
@enum_name = " put(#{ENUM_NAME}, \"#{system_enum_name}\");"
|
83
|
+
@enum_values = " put(#{ENUM_VALUES}, getEnumValues(#{system_enum_name}.values()));"
|
84
|
+
elsif value == Blufin::YmlSchemaValidator::TYPE_ENUM_SYSTEM
|
85
|
+
# This only applies to Embedded Objects.
|
86
|
+
enum_values = @yml_enum_scanner.get_enum_system_values_for(column_data[:type_java])
|
87
|
+
converted_type = 'ENUM_SYSTEM'
|
88
|
+
max_length = enum_values.max_by(&:length).length
|
89
|
+
@import_statements << "import #{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS}.#{column_data[:type_java]};"
|
90
|
+
@enum_name = " put(#{ENUM_NAME}, \"#{column_data[:type_java]}\");"
|
91
|
+
@enum_values = " put(#{ENUM_VALUES}, getEnumValues(#{column_data[:type_java]}.values()));"
|
92
|
+
elsif [
|
93
|
+
Blufin::ScannerJavaEmbeddedObjects::OBJECT,
|
94
|
+
Blufin::ScannerJavaEmbeddedObjects::OBJECT_LIST,
|
95
|
+
Blufin::ScannerJavaEmbeddedObjects::OBJECT_LINK,
|
96
|
+
].include?(value)
|
97
|
+
# Do Nothing. Fix for @Embedded Meta-Writer.
|
98
|
+
else
|
99
|
+
raise RuntimeError, "Unrecognized type in #{__FILE__}: #{value}"
|
100
|
+
end
|
101
|
+
@type = " put(#{TYPE}, DataType.#{converted_type});"
|
102
|
+
@max_length = " put(#{MAX_LENGTH}, #{max_length.to_i});" unless max_length.nil?
|
103
|
+
end
|
104
|
+
|
105
|
+
def handle_type_where_implied(table, column_name)
|
106
|
+
if column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/
|
107
|
+
@type = " put(#{TYPE}, DataType.OBJECT);"
|
108
|
+
elsif column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/
|
109
|
+
@type = " put(#{TYPE}, DataType.OBJECT_LIST);"
|
110
|
+
elsif column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
|
111
|
+
@type = " put(#{TYPE}, DataType.OBJECT_LINK);"
|
112
|
+
@link = " put(#{LINK}, \"#{Blufin::YmlCommon::get_link_table_name(table, column_name)}\");"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def handle_flag(value)
|
117
|
+
if value != '' && !value.nil?
|
118
|
+
flags_array = []
|
119
|
+
flags_data = Blufin::YmlCommon::extract_flags(value)[0]
|
120
|
+
flags_array << FLAG_AUTO_INCREMENT unless flags_data.auto_increment.nil?
|
121
|
+
flags_array << FLAG_INDEX unless flags_data.index.nil?
|
122
|
+
flags_array << FLAG_NULLABLE unless flags_data.nullable.nil?
|
123
|
+
flags_array << FLAG_PRIMARY_KEY unless flags_data.primary_key.nil?
|
124
|
+
flags_array << FLAG_UNIQUE unless flags_data.unique.nil?
|
125
|
+
if flags_array.any?
|
126
|
+
@import_statements << 'import java.util.Arrays;'
|
127
|
+
@flag = " put(#{FLAG}, Arrays.asList("
|
128
|
+
flags_array.each do |flag|
|
129
|
+
@flag += "#{flag}, "
|
130
|
+
end
|
131
|
+
@flag = @flag[0...-2]
|
132
|
+
@flag += '));'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def handle_fkey(value)
|
138
|
+
@fkey = " put(#{FKEY}, \"#{value.to_s.gsub('"', '\"')}\");"
|
139
|
+
end
|
140
|
+
|
141
|
+
def handle_required(schema, table, value, table_data)
|
142
|
+
@required = " put(#{REQUIRED}, true);"
|
143
|
+
end
|
144
|
+
|
145
|
+
def handle_required_if(schema, table, value, table_data)
|
146
|
+
value_split = value.split('=')
|
147
|
+
enum_value = table_data[value_split[0]][Blufin::YmlSchemaValidator::TYPE]
|
148
|
+
if enum_value =~ /#{Blufin::YmlSchemaValidator::REGEX_ENUM}/
|
149
|
+
enum_class_name = "#{Blufin::Strings::snake_case_to_camel_case(table)}#{Blufin::Strings.snake_case_to_camel_case(value_split[0].dup)}"
|
150
|
+
enum_package = get_package(@site, schema, 'enums', Blufin::SiteServices::SDK)
|
151
|
+
elsif enum_value =~ /#{Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM}/
|
152
|
+
enum_class_name = Blufin::Strings.snake_case_to_camel_case(value_split[0].dup)
|
153
|
+
enum_package = get_package(@site, schema, 'enums', Blufin::SiteServices::SDK)
|
154
|
+
elsif enum_value =~ /#{Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM}/
|
155
|
+
enum_class_name = Blufin::YmlCommon::enum_name_extractor(enum_value)
|
156
|
+
enum_package = Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS
|
157
|
+
else
|
158
|
+
raise RuntimeError, "'#{enum_value}' doesn't match regex for ENUM, ENUM_CUSTOM or ENUM_SYSTEM."
|
159
|
+
end
|
160
|
+
|
161
|
+
@required_if = " put(#{REQUIRED_IF}, Pair.of(FIELD_#{value_split[0].upcase}, #{enum_class_name}.#{value_split[1].upcase}));"
|
162
|
+
@import_statements << 'import org.blufin.base.helper.Pair;'
|
163
|
+
@import_statements << "import #{enum_package}.#{enum_class_name};"
|
164
|
+
end
|
165
|
+
|
166
|
+
def handle_encrypted(value)
|
167
|
+
raise RuntimeError, "Encrypted value is something other than 'true' \xe2\x86\x92 #{value}" unless value == 'true' || value == true
|
168
|
+
@encrypted = " put(#{ENCRYPTED}, true);"
|
169
|
+
end
|
170
|
+
|
171
|
+
def handle_transient(value)
|
172
|
+
@transient = " put(#{TRANSIENT}, \"#{value[0]}.#{value[1]}\");"
|
173
|
+
end
|
174
|
+
|
175
|
+
def handle_child_of(value)
|
176
|
+
@child_of = " put(#{CHILD_OF}, \"#{value}\");"
|
177
|
+
end
|
178
|
+
|
179
|
+
def handle_child_type(value)
|
180
|
+
raise RuntimeError, "@child_type is being set twice! Was originally: #{@child_type} , now being set to: #{value}" unless @child_type.nil?
|
181
|
+
@child_type = value
|
182
|
+
end
|
183
|
+
|
184
|
+
# This build the "hierarchy" Array in the MetaData constructors.
|
185
|
+
# schema_tables_array is an Array like [app.data_center, app.db, common.cron]...
|
186
|
+
# @return Array (of Data)
|
187
|
+
def extract_hierarchy(schema, table, dependents_array, schema_tables_array)
|
188
|
+
hierarchy = ["\"#{table}\""]
|
189
|
+
hierarchy_nested_only = []
|
190
|
+
unless dependents_array.nil?
|
191
|
+
dependents_array.each do |dependent|
|
192
|
+
ds_array = []
|
193
|
+
ds_current = ''
|
194
|
+
ds_buffer = ''
|
195
|
+
ds = dependent.split('_')
|
196
|
+
ds_counter = 0
|
197
|
+
ds_levels = []
|
198
|
+
ds.each do |n|
|
199
|
+
ds_current += "_#{n}"
|
200
|
+
ds_current = ds_current.gsub(/^_/, '')
|
201
|
+
ds_buffer += "_#{n}"
|
202
|
+
ds_buffer = ds_buffer.gsub(/^_/, '')
|
203
|
+
if schema_tables_array.include?("#{schema}.#{ds_current}")
|
204
|
+
if ds_current =~ /^#{table}/
|
205
|
+
ds_counter = ds_counter + 1
|
206
|
+
ds_array << ds_buffer
|
207
|
+
ds_levels << [ds_counter, ds_array.join('_')]
|
208
|
+
ds_buffer = ''
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
hierarchy << "\"#{ds_array.join('/')}\""
|
213
|
+
hierarchy_nested_only << ds_array.join('_')
|
214
|
+
end
|
215
|
+
end
|
216
|
+
hierarchy.uniq!
|
217
|
+
hierarchy.sort!
|
218
|
+
[hierarchy, hierarchy_nested_only]
|
219
|
+
end
|
220
|
+
|
221
|
+
def generate_content(content, embedded, consts, fields, hierarchy, hierarchy_nested_only, schema, table, class_name, import_statements, child_type)
|
222
|
+
|
223
|
+
parent = @schema_resources["#{schema}.#{table}"][:parent]
|
224
|
+
parent = (parent.nil? || parent.strip == '') ? 'null' : "\"#{parent}\""
|
225
|
+
|
226
|
+
if import_statements.any?
|
227
|
+
import_statements.uniq!
|
228
|
+
content = content.push(*import_statements)
|
229
|
+
content << ''
|
230
|
+
end
|
231
|
+
|
232
|
+
content << 'import java.util.HashMap;'
|
233
|
+
content << 'import java.text.MessageFormat;'
|
234
|
+
content << 'import lombok.Getter;'
|
235
|
+
content << 'import org.blufin.base.enums.SchemaType;'
|
236
|
+
content << ''
|
237
|
+
content << "public final class #{class_name} extends Abstract#{Blufin::YmlJavaMetaWriter::META_DATA} {"
|
238
|
+
content << ''
|
239
|
+
content << ' @Getter'
|
240
|
+
content << " private static final #{class_name} instance = new #{class_name}();"
|
241
|
+
content << ''
|
242
|
+
|
243
|
+
if consts.any?
|
244
|
+
consts.each do |const|
|
245
|
+
content << const
|
246
|
+
end
|
247
|
+
content << ''
|
248
|
+
end
|
249
|
+
|
250
|
+
content << " private #{class_name}() {"
|
251
|
+
content << ''
|
252
|
+
|
253
|
+
# Hacky-fix for test classes. DO NOT remove this or Java won't compile.
|
254
|
+
constructor_schema = (schema == Blufin::YmlSchemaValidator::MOCK) ? 'null' : "SchemaType.#{schema.upcase}"
|
255
|
+
content << " super(#{constructor_schema}, \"#{table}\", #{parent}, Arrays.asList(#{hierarchy.join(', ')}), #{child_type.nil? ? 'null' : child_type});"
|
256
|
+
content << ''
|
257
|
+
|
258
|
+
if fields.any?
|
259
|
+
fields.each_with_index do |field, idx|
|
260
|
+
if idx == fields.length - 1
|
261
|
+
content << field[0...-1]
|
262
|
+
else
|
263
|
+
content << field
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
content << ' }'
|
269
|
+
|
270
|
+
if hierarchy_nested_only.any?
|
271
|
+
content << ''
|
272
|
+
content << ' @Override'
|
273
|
+
content << ' public AbstractMetaData getNestedMetaData(String nestedTable) {'
|
274
|
+
content << ''
|
275
|
+
content << ' switch (nestedTable) {'
|
276
|
+
content << ''
|
277
|
+
hierarchy_nested_only.each do |n|
|
278
|
+
content << " case \"#{n}\":"
|
279
|
+
content << " return #{embedded}#{Blufin::Strings::snake_case_to_camel_case(n)}MetaData.getInstance();"
|
280
|
+
content << ''
|
281
|
+
end
|
282
|
+
content << ' default:'
|
283
|
+
content << " throw new RuntimeException(MessageFormat.format(\"#{embedded}#{class_name} doesn''t have nested metadata for table: {0}\", nestedTable));"
|
284
|
+
content << ' }'
|
285
|
+
content << ' }'
|
286
|
+
|
287
|
+
else
|
288
|
+
content << ''
|
289
|
+
content << ' @Override'
|
290
|
+
content << ' public AbstractMetaData getNestedMetaData(String nestedTable) {'
|
291
|
+
content << ''
|
292
|
+
content << " throw new RuntimeException(\"Nested metadata not available for #{embedded}#{class_name}. This method should never be called manually.\");"
|
293
|
+
content << ' }'
|
294
|
+
end
|
295
|
+
content << '}'
|
296
|
+
content
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlOutputter
|
4
|
+
|
5
|
+
include Columnist
|
6
|
+
|
7
|
+
AUTO = 'AUTO'
|
8
|
+
CUSTOM = 'CUSTOM'
|
9
|
+
SYSTEM = 'SYSTEM'
|
10
|
+
|
11
|
+
def initialize(site)
|
12
|
+
|
13
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
14
|
+
|
15
|
+
@auto_increment = []
|
16
|
+
@auto_increment_indexed = []
|
17
|
+
|
18
|
+
@resources = []
|
19
|
+
|
20
|
+
@schema_fks_links = {}
|
21
|
+
|
22
|
+
@yml_enum_scanner = Blufin::ScannerJavaEnums.new(@site)
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Renders the AUTO_INCREMENT table.
|
27
|
+
# @return void
|
28
|
+
def show_auto_increment
|
29
|
+
|
30
|
+
cnt = 0
|
31
|
+
max = [@auto_increment.length, @auto_increment_indexed.length].max.to_i
|
32
|
+
|
33
|
+
Blufin::Terminal::custom('SUMMARY', 23, Blufin::YmlSchemaValidator::FLAG_AUTO_INCREMENT, "Below you can see which tables have what #{Blufin::Terminal::format_highlight(Blufin::YmlSchemaValidator::FLAG_AUTO_INCREMENT)} values applied")
|
34
|
+
|
35
|
+
table(:border => false) do
|
36
|
+
|
37
|
+
row do
|
38
|
+
column('', :width => 4)
|
39
|
+
column('AUTO_INCREMENT', :width => 60, :color => 34)
|
40
|
+
column('AUTO_INCREMENT(?)', :width => 60, :color => 34)
|
41
|
+
end
|
42
|
+
|
43
|
+
while cnt + 1 < max
|
44
|
+
row do
|
45
|
+
column('')
|
46
|
+
column(@auto_increment[cnt], :color => 240)
|
47
|
+
column(@auto_increment_indexed[cnt], :color => 240)
|
48
|
+
end
|
49
|
+
cnt = cnt + 1
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "\x1B[0m"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Renders a summary of all enums that are available (including their possible values).
|
58
|
+
# @return void
|
59
|
+
def show_enums
|
60
|
+
|
61
|
+
terminal_width = Blufin::Terminal::get_terminal_width
|
62
|
+
|
63
|
+
Blufin::Terminal::error('Cannot display data because terminal window is too narrow.', ["Current width is: #{Blufin::Terminal::format_highlight(terminal_width)}", "Minimum width is: #{Blufin::Terminal::format_highlight('90')}"], true) if terminal_width < 90 && all
|
64
|
+
Blufin::Terminal::custom('SUMMARY', 58, 'ENUMS', "Below is a list of all available #{Blufin::Terminal::format_highlight('ENUMS')} for \x1B[38;5;106m#{Blufin::SiteResolver::get_site_title(@site)}\x1B[0m.")
|
65
|
+
|
66
|
+
terminal_width = Blufin::Terminal::get_terminal_width
|
67
|
+
|
68
|
+
all_enums = []
|
69
|
+
|
70
|
+
auto_enums = @yml_enum_scanner.get_auto_enums
|
71
|
+
custom_enums = @yml_enum_scanner.get_custom_enums
|
72
|
+
system_enums = @yml_enum_scanner.get_system_enums
|
73
|
+
|
74
|
+
auto_enums.keys.each { |enum| all_enums << enum }
|
75
|
+
custom_enums.keys.each { |enum| all_enums << enum }
|
76
|
+
system_enums.keys.each { |enum| all_enums << enum }
|
77
|
+
|
78
|
+
max_enum_width = all_enums.max_by(&:length).length
|
79
|
+
value_column_max_width = terminal_width - 30 - max_enum_width
|
80
|
+
|
81
|
+
enum_column_width = ((max_enum_width + 5) < 10) ? 10 : (max_enum_width + 5)
|
82
|
+
|
83
|
+
table(:border => false) do
|
84
|
+
|
85
|
+
row do
|
86
|
+
column('', :width => 17, :align => 'right')
|
87
|
+
column('', :width => 1, :color => 255)
|
88
|
+
column('', :width => enum_column_width, :color => 240, :align => 'left')
|
89
|
+
column('', :width => value_column_max_width)
|
90
|
+
end
|
91
|
+
|
92
|
+
show_enums_common_table(custom_enums, value_column_max_width, AUTO)
|
93
|
+
show_enums_common_table(auto_enums, value_column_max_width, CUSTOM)
|
94
|
+
show_enums_common_table(system_enums, value_column_max_width, SYSTEM)
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
# Renders a summary of all resource end-points exposed by the API.
|
102
|
+
# @return void
|
103
|
+
def show_resources(as_json = false)
|
104
|
+
|
105
|
+
if @resources.any?
|
106
|
+
|
107
|
+
if as_json
|
108
|
+
|
109
|
+
puts @resources.inspect
|
110
|
+
|
111
|
+
else
|
112
|
+
|
113
|
+
width_schema = []
|
114
|
+
width_group = []
|
115
|
+
width_resource = []
|
116
|
+
width_type = []
|
117
|
+
|
118
|
+
# Get column widths (to make as narrow as possible).
|
119
|
+
@resources.each do |data|
|
120
|
+
data.each do |key, resource|
|
121
|
+
width_schema << resource[:schema].length
|
122
|
+
width_group << resource[:resource].split('/')[0].length
|
123
|
+
width_resource << resource[:resource].length
|
124
|
+
width_type << resource[:type].length
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
Blufin::Terminal::custom('SUMMARY', 161, 'RESOURCES', "Below is a summary of the final #{Blufin::Terminal::format_highlight('RESOURCE STRUCTURE')}")
|
129
|
+
|
130
|
+
table(:border => false) do
|
131
|
+
|
132
|
+
current_group = nil
|
133
|
+
|
134
|
+
@resources.each do |data|
|
135
|
+
|
136
|
+
data.each do |key, resource|
|
137
|
+
|
138
|
+
group = resource[:resource].split('/')[0]
|
139
|
+
extra = ''
|
140
|
+
extra_color = 240
|
141
|
+
|
142
|
+
case resource[:type]
|
143
|
+
when Blufin::YmlSchemaValidator::RESOURCE_TYPE_PARENT
|
144
|
+
type_text = "\xe2\x80\x94"
|
145
|
+
type_color = 240
|
146
|
+
when Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT
|
147
|
+
type_text = Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT
|
148
|
+
type_color = 147
|
149
|
+
when Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST
|
150
|
+
type_text = Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST
|
151
|
+
type_color = 197
|
152
|
+
when Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LINK
|
153
|
+
type_text = Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LINK
|
154
|
+
type_color = 118
|
155
|
+
else
|
156
|
+
raise RuntimeError, "Type not found in \xe2\x86\x92 show_resources()."
|
157
|
+
end
|
158
|
+
|
159
|
+
# If this is a LINKED table, show list of tables where it's referenced from.
|
160
|
+
if resource[:type] == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LINK
|
161
|
+
unless @schema_fks_links[key].nil?
|
162
|
+
extra = []
|
163
|
+
@schema_fks_links[key].each do |table|
|
164
|
+
extra << table.split('.')[1]
|
165
|
+
end
|
166
|
+
extra = "\xe2\x86\x92 #{extra.join(', ')}"
|
167
|
+
extra_color = 220
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
row do
|
172
|
+
column((group != current_group) ? "#{resource[:schema]} \xe2\x86\x92" : '', :color => 250, :width => (width_schema.max.to_i) + 4, :align => 'right')
|
173
|
+
column((group != current_group) ? group : '', :color => 154, :width => (width_group.max.to_i) + 2)
|
174
|
+
column(resource[:resource], :color => 240, :width => (width_resource.max.to_i) + 2)
|
175
|
+
column("#{type_text}", :color => type_color, :width => width_type.max.to_i, :align => 'right')
|
176
|
+
column(extra, :color => extra_color, :width => 100)
|
177
|
+
end
|
178
|
+
|
179
|
+
current_group = group
|
180
|
+
current_schema = resource[:schema]
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
row do
|
187
|
+
column('')
|
188
|
+
column('')
|
189
|
+
column('')
|
190
|
+
column('')
|
191
|
+
column('')
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
|
202
|
+
def add_auto_increment_table(schema, table)
|
203
|
+
@auto_increment << "#{schema}.#{table}"
|
204
|
+
end
|
205
|
+
|
206
|
+
def add_auto_increment_indexed_table(schema, table, amount)
|
207
|
+
@auto_increment_indexed << "(#{amount}) \xe2\x86\x92 #{schema}.#{table}"
|
208
|
+
end
|
209
|
+
|
210
|
+
def add_resource(key, data)
|
211
|
+
@resources << {key => data}
|
212
|
+
end
|
213
|
+
|
214
|
+
def set_schema_fks_links(hash)
|
215
|
+
@schema_fks_links = hash
|
216
|
+
end
|
217
|
+
|
218
|
+
private
|
219
|
+
|
220
|
+
def show_enums_common_table(enum_hash, value_column_width, type)
|
221
|
+
|
222
|
+
case type
|
223
|
+
when AUTO
|
224
|
+
text_type = 'ENUM_AUTO'
|
225
|
+
color_one = 97
|
226
|
+
color_two = 183
|
227
|
+
when CUSTOM
|
228
|
+
text_type = 'ENUM_CUSTOM'
|
229
|
+
color_one = 34
|
230
|
+
color_two = 118
|
231
|
+
when SYSTEM
|
232
|
+
text_type = 'ENUM_SYSTEM'
|
233
|
+
color_one = 31
|
234
|
+
color_two = 153
|
235
|
+
else
|
236
|
+
raise RuntimeError, "Unrecognized enum type: #{type}"
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
enum_hash.each do |enum, values|
|
241
|
+
|
242
|
+
vals = values.dup
|
243
|
+
vals_all = []
|
244
|
+
row_output = []
|
245
|
+
vals_per_row = vals.length.to_f
|
246
|
+
|
247
|
+
vals.each { |val| vals_all << val }
|
248
|
+
|
249
|
+
next unless vals_all.any?
|
250
|
+
|
251
|
+
# The length of the longest ENUM value (plus 2) -- rounded up to nearest 5.
|
252
|
+
vals_max = vals_all.max_by(&:length).length + 2
|
253
|
+
vals_max = vals_max + (5 - (vals_max % 5)) if (vals_max % 5) > 0
|
254
|
+
|
255
|
+
# The maximum number of values we can have in a row before we run out of Terminal.
|
256
|
+
cols_max = (value_column_width / vals_max).to_f
|
257
|
+
|
258
|
+
while vals_per_row > cols_max do
|
259
|
+
vals_per_row = vals_per_row / 2
|
260
|
+
end
|
261
|
+
|
262
|
+
number_of_rows = (vals.length / vals_per_row).to_i
|
263
|
+
|
264
|
+
raise RuntimeError, '(number_of_rows * vals_per_row) should not be less than vals.length' if (number_of_rows * vals_per_row) < vals.length
|
265
|
+
|
266
|
+
number_of_rows.times do
|
267
|
+
output = ''
|
268
|
+
vals_per_row.ceil.times do
|
269
|
+
output << vals.shift.to_s.ljust(vals_max, ' ')
|
270
|
+
end
|
271
|
+
row_output << output if output.strip.length > 0
|
272
|
+
end
|
273
|
+
|
274
|
+
row do
|
275
|
+
column(text_type, :color => color_one)
|
276
|
+
column('→')
|
277
|
+
column("#{enum} ", :color => color_two)
|
278
|
+
column(row_output[0], :color => 244)
|
279
|
+
end
|
280
|
+
|
281
|
+
row_output.shift
|
282
|
+
|
283
|
+
if row_output.length > 1
|
284
|
+
row_output.each do |val|
|
285
|
+
row do
|
286
|
+
column('')
|
287
|
+
column('')
|
288
|
+
column('')
|
289
|
+
column(val, :color => 244)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
row do
|
295
|
+
column('')
|
296
|
+
column('')
|
297
|
+
column('')
|
298
|
+
column('')
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|