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,161 @@
1
+ module Blufin
2
+
3
+ class YmlJavaEnumWriter < Blufin::YmlWriterBase
4
+
5
+ SERVICE = Blufin::SiteServices::SDK_INTERNAL
6
+ PACKAGE_AUTO = 'enums'
7
+ PACKAGE_CUSTOM = 'enums'
8
+
9
+ # @return void
10
+ def initialize(site, schema_data)
11
+
12
+ @schema_data = schema_data
13
+
14
+ raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
15
+
16
+ @site = Blufin::SiteResolver::validate_site(site)
17
+ @site_name = Blufin::SiteResolver::get_site_name(@site)
18
+ @site_domain = Blufin::SiteResolver::get_site_domain(@site)
19
+ @site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
20
+
21
+ # Wipe out all previous files.
22
+ Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
23
+ paths_to_wipe_out = %W(#{get_java_path(@site, schema, SERVICE, PACKAGE_AUTO)})
24
+ paths_to_wipe_out.each do |path_to_wipe_out|
25
+ if Blufin::Files::path_exists(path_to_wipe_out)
26
+ if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
27
+ Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
36
+ # @return void
37
+ def write
38
+
39
+ @schema_data.each do |schema, schema_data|
40
+
41
+ schema_data.each_with_index do |(table, table_data), idx|
42
+
43
+ if table_data.length > 0
44
+
45
+ table_data.each do |column_name, column_data|
46
+
47
+ # Skip Placeholders
48
+ next if column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/ || column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
49
+
50
+ field_camel_case = Blufin::Strings.snake_case_to_camel_case(column_name.dup)
51
+
52
+ @type = column_data[Blufin::YmlSchemaValidator::TYPE]
53
+
54
+ if @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
55
+ enum_class_name = "#{Blufin::Strings::snake_case_to_camel_case(table)}#{field_camel_case}"
56
+ write_enum_class(enum_class_name, @type, schema)
57
+ elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM
58
+ enum_value = Blufin::YmlCommon::enum_name_extractor(@type)
59
+ enum_file = "#{get_java_path(@site, schema, Blufin::SiteServices::SDK_CORE, PACKAGE_CUSTOM)}/#{enum_value}.java"
60
+ write_enum_custom_class(enum_value, schema) unless Blufin::Files::file_exists(enum_file)
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ private
74
+
75
+ def write_enum_class(enum_class_name, type, schema)
76
+
77
+ enum_values = Blufin::YmlCommon::enum_value_extractor(type, @site)
78
+ enum_class_name_lower = "#{enum_class_name[0, 1].downcase}#{enum_class_name[1..-1]}"
79
+
80
+ enum_lines = []
81
+
82
+ enum_lines << "package #{get_package(@site, schema, PACKAGE_AUTO, SERVICE)};"
83
+ enum_lines << ''
84
+ enum_lines << 'import lombok.Getter;'
85
+ enum_lines << ''
86
+ enum_lines << 'import java.util.HashMap;'
87
+ enum_lines << 'import java.util.Map;'
88
+ enum_lines << ''
89
+ enum_lines << "public enum #{enum_class_name} {"
90
+ enum_lines << ''
91
+ enum_values.each_with_index do |enum_value, idx|
92
+ if idx == (enum_values.length - 1)
93
+ enum_lines << " #{write_enum_name(enum_value)}(\"#{enum_value}\");"
94
+ else
95
+ enum_lines << " #{write_enum_name(enum_value)}(\"#{enum_value}\"),"
96
+ end
97
+ end
98
+ enum_lines << ''
99
+ enum_lines << " private static final Map<String, #{enum_class_name}> #{enum_class_name_lower}Map = new HashMap<>();"
100
+ enum_lines << ''
101
+ enum_lines << ' @Getter'
102
+ enum_lines << ' private final String name;'
103
+ enum_lines << ''
104
+ enum_lines << ' static {'
105
+ enum_lines << ''
106
+ enum_lines << " for (#{enum_class_name} #{enum_class_name_lower} : #{enum_class_name}.values()) {"
107
+ enum_lines << ''
108
+ enum_lines << " #{enum_class_name_lower}Map.put(#{enum_class_name_lower}.toString(), #{enum_class_name_lower});"
109
+ enum_lines << ' }'
110
+ enum_lines << ' }'
111
+ enum_lines << ''
112
+ enum_lines << " #{enum_class_name}(String name) {"
113
+ enum_lines << ''
114
+ enum_lines << ' this.name = name;'
115
+ enum_lines << ' }'
116
+ enum_lines << ''
117
+ enum_lines << " public static final #{enum_class_name} get(String name) {"
118
+ enum_lines << ''
119
+ enum_lines << " return #{enum_class_name_lower}Map.get(name);"
120
+ enum_lines << ' }'
121
+ enum_lines << ''
122
+ enum_lines << ' @Override'
123
+ enum_lines << ' public final String toString() {'
124
+ enum_lines << ''
125
+ enum_lines << ' return name;'
126
+ enum_lines << ' }'
127
+ enum_lines << '}'
128
+
129
+ full_file_path = "#{get_java_path(@site, schema, SERVICE, PACKAGE_AUTO)}/#{enum_class_name}.java"
130
+
131
+ write_file_java(full_file_path, enum_lines, schema == Blufin::YmlSchemaValidator::MOCK).gsub(@site_location, '')
132
+
133
+ end
134
+
135
+ # Writes a blank CUSTOM_ENUM file in the sdk-core (if it's defined in the schema but the actual file doesn't exist).
136
+ # @return void
137
+ def write_enum_custom_class(enum_class_name, schema)
138
+
139
+ enum_lines = []
140
+ enum_lines << "package #{get_package(@site, schema, PACKAGE_CUSTOM, Blufin::SiteServices::SDK_CORE)};"
141
+ enum_lines << ''
142
+ enum_lines << "public enum #{enum_class_name} {"
143
+ enum_lines << ''
144
+ enum_lines << '}'
145
+
146
+ full_file_path = "#{get_java_path(@site, schema, Blufin::SiteServices::SDK_CORE, PACKAGE_CUSTOM)}/#{enum_class_name}.java"
147
+
148
+ write_file_java(full_file_path, enum_lines, schema == Blufin::YmlSchemaValidator::MOCK).gsub(@site_location, '')
149
+ Blufin::Terminal::command("git add #{full_file_path}", get_base_path(@site), false, false)
150
+
151
+ end
152
+
153
+ # ENUM -> ENUM
154
+ # EnumValue -> ENUM_VALUE
155
+ def write_enum_name(enum_value)
156
+ enum_value.upcase == enum_value ? enum_value : Blufin::Strings::camel_case_to_snake_case(enum_value).upcase
157
+ end
158
+
159
+ end
160
+
161
+ end
@@ -0,0 +1,59 @@
1
+ module Blufin
2
+
3
+ class YmlJavaJsDependencyWriter < Blufin::YmlWriterBase
4
+
5
+ # Initialize the class.
6
+ # @return void
7
+ def initialize(site)
8
+
9
+ @site = Blufin::SiteResolver::validate_site(site)
10
+ @site_name = Blufin::SiteResolver::get_site_name(@site)
11
+ @site_domain = Blufin::SiteResolver::get_site_domain(@site)
12
+ @site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
13
+
14
+ # Wipe out all previous files.
15
+ # Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
16
+ # %W(
17
+ # #{@embedded_path}/base
18
+ # #{@embedded_path}/field
19
+ # #{@embedded_path}/filter
20
+ # #{@embedded_path}/mapper
21
+ # #{@embedded_path}/refiner
22
+ # #{@embedded_path}/service
23
+ # #{@embedded_path}/sort
24
+ # ).each do |path_to_wipe_out|
25
+ # if Blufin::Files::path_exists(path_to_wipe_out)
26
+ # if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
27
+ # Blufin::Terminal::command('rm *', path_to_wipe_out, false, false) unless path_to_wipe_out == "#{@embedded_path}/dto" # Safe-guard to prevent accidental deletion of /dto folder.
28
+ # end
29
+ # end
30
+ # end
31
+ # end
32
+
33
+ @template = <<TEMPLATE
34
+ package #{PLACEHOLDER_PACKAGE};
35
+
36
+ public class #{PLACEHOLDER_CLASS} {
37
+
38
+ }
39
+ TEMPLATE
40
+
41
+ end
42
+
43
+ # Write the file(s).
44
+ # @return void
45
+ def write
46
+
47
+ # class_name = 'MessageType'
48
+ #
49
+ # contents = @template
50
+ # contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, PACKAGE, SERVICE))
51
+ # contents = contents.gsub(PLACEHOLDER_CLASS, class_name)
52
+ #
53
+ # write_file_java("#{get_java_path(@site, nil, SERVICE, PACKAGE)}/#{class_name}.java", Blufin::YmlCommon::convert_string_to_line_array(contents))
54
+
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,106 @@
1
+ module Blufin
2
+
3
+ class YmlJavaMessageTypeWriter < Blufin::YmlWriterBase
4
+
5
+ SERVICE = Blufin::SiteServices::LIB
6
+ PACKAGE = 'enums.system'
7
+
8
+ PLACEHOLDER_ONE = '{{--PLACEHOLDER-ONE--}}'
9
+ PLACEHOLDER_TWO = '{{--PLACEHOLDER-TWO--}}'
10
+
11
+ # Initialize the class.
12
+ # @return void
13
+ def initialize(site)
14
+
15
+ @site = Blufin::SiteResolver::validate_site(site)
16
+ @site_name = Blufin::SiteResolver::get_site_name(@site)
17
+ @site_domain = Blufin::SiteResolver::get_site_domain(@site)
18
+ @site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
19
+
20
+ @class_name = 'MessageType'
21
+
22
+ @filename = "#{get_java_path(@site, nil, SERVICE, PACKAGE)}/#{@class_name}.java"
23
+
24
+ # Wipe out previous file (if exists).
25
+ Blufin::Files::delete_file(@filename)
26
+
27
+ @template = <<TEMPLATE
28
+ package #{PLACEHOLDER_PACKAGE};
29
+
30
+ import org.blufin.base.interfaces.AbstractMessageType;
31
+ import lombok.Getter;
32
+
33
+ import java.util.HashMap;
34
+ import java.util.Map;
35
+
36
+ public enum #{@class_name} implements AbstractMessageType {
37
+
38
+ #{PLACEHOLDER_ONE}
39
+
40
+ private static final Map<String, #{@class_name}> map = new HashMap<>();
41
+
42
+ @Getter
43
+ private String name;
44
+
45
+ static {
46
+
47
+ #{PLACEHOLDER_TWO}
48
+ }
49
+
50
+ /**
51
+ * @param name
52
+ */
53
+ #{@class_name}(String name) {
54
+
55
+ this.name = name;
56
+ }
57
+
58
+ /**
59
+ * Get MessageType by its String representation.
60
+ * @param name
61
+ */
62
+ public static MessageType get(String name) {
63
+
64
+ return map.get(name);
65
+ }
66
+
67
+ @Override
68
+ public String toString() {
69
+
70
+ return name;
71
+ }
72
+ }
73
+ TEMPLATE
74
+
75
+ end
76
+
77
+ # Write the file(s).
78
+ # @return void
79
+ def write
80
+
81
+ ph1 = []
82
+ ph2 = []
83
+
84
+ message_types = Blufin::YmlConfigValidator::get_message_types.keys
85
+
86
+ # Don't write the class if there are no message types.
87
+ return if message_types.nil? || message_types.length == 0
88
+
89
+ message_types.each_with_index do |message_type, idx|
90
+ comma_or_semicolon = (idx == (message_types.length - 1)) ? ';' : ','
91
+ ph1 << " #{message_type.upcase}(\"#{message_type.upcase}\")#{comma_or_semicolon}"
92
+ ph2 << " map.put(\"#{message_type.upcase}\", MessageType.#{message_type.upcase});"
93
+ end
94
+
95
+ contents = @template
96
+ contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, PACKAGE, SERVICE))
97
+ contents = contents.gsub(PLACEHOLDER_ONE, Blufin::YmlCommon::convert_line_array_to_string(ph1))
98
+ contents = contents.gsub(PLACEHOLDER_TWO, Blufin::YmlCommon::convert_line_array_to_string(ph2))
99
+
100
+ write_file_java(@filename, Blufin::YmlCommon::convert_string_to_line_array(contents))
101
+
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,173 @@
1
+ module Blufin
2
+
3
+ class YmlJavaMetaWriter < Blufin::YmlMetaWriterBase
4
+
5
+ SERVICE = Blufin::SiteServices::SDK_INTERNAL
6
+ PACKAGE = 'metadata'
7
+ META_DATA = 'MetaData'
8
+
9
+ # @return void
10
+ def initialize(site, schema_data, schema_resources)
11
+
12
+ @schema_data = schema_data
13
+ @schema_resources = schema_resources
14
+
15
+ raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
16
+ raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash)
17
+
18
+ @site = Blufin::SiteResolver::validate_site(site)
19
+ @site_name = Blufin::SiteResolver::get_site_name(@site)
20
+ @site_domain = Blufin::SiteResolver::get_site_domain(@site)
21
+ @site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
22
+
23
+ @embedded_data = Blufin::SiteEmbedded::get_data
24
+ @embedded_path = "#{Blufin::Config::get_path('Paths', 'BlufinJava')}/#{Blufin::ScannerJavaEmbeddedObjects::PATH_TO_EMBEDDED}"
25
+
26
+ @yml_enum_scanner = Blufin::ScannerJavaEnums.new(@site)
27
+
28
+ # Wipe out all previous files.
29
+ Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
30
+ paths_to_wipe_out = %W(#{get_java_path(@site, schema, SERVICE, PACKAGE)})
31
+ paths_to_wipe_out.each do |path_to_wipe_out|
32
+ if Blufin::Files::path_exists(path_to_wipe_out)
33
+ if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
34
+ Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ # @return void
43
+ def write
44
+
45
+ @schema_data.each do |schema, schema_data|
46
+
47
+ schema_data.each do |(table, table_data)|
48
+
49
+ if table_data.is_a?(Hash) && table_data.length > 0
50
+
51
+ @import_statements = ['import org.blufin.sdk.base.AbstractMetaData;', 'import org.blufin.base.enums.DataType;']
52
+ @child_type = nil
53
+
54
+ consts = []
55
+ fields = []
56
+
57
+ table_data.each do |column_name, column_data|
58
+
59
+ @type = nil
60
+ @flag = nil
61
+ @fkey = nil
62
+ @link = nil
63
+ @encrypted = nil
64
+ @max_length = nil
65
+ @transient = nil
66
+ @child_of = nil
67
+ @description = nil
68
+ @required = nil
69
+ @required_if = nil
70
+ @decimal_distribution = nil
71
+ @enum_name = nil
72
+ @enum_values = nil
73
+
74
+ # Handle Placeholders
75
+ if column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/
76
+ column_name_dup = "#{column_name.dup.gsub('[]', '').split('.')[1]}"
77
+ consts << " public static final String FIELD_#{column_name_dup.upcase} = \"#{column_name_dup}\";"
78
+ fields << " metaData.put(FIELD_#{column_name_dup.upcase}, new HashMap<String, Object>() {{"
79
+ elsif column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/
80
+ column_name_dup = "#{column_name.dup.gsub('[]', '').split('.')[1]}_list"
81
+ consts << " public static final String FIELD_#{column_name_dup.upcase} = \"#{column_name_dup}\";"
82
+ fields << " metaData.put(FIELD_#{column_name_dup.upcase}, new HashMap<String, Object>() {{"
83
+ elsif column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
84
+ column_name_dup = "#{column_name.dup.gsub("[#{Blufin::YmlSchemaValidator::LINK}]", '').split('.')[1]}_list"
85
+ consts << " public static final String FIELD_#{column_name_dup.upcase} = \"#{column_name_dup}\";"
86
+ fields << " metaData.put(FIELD_#{column_name_dup.upcase}, new HashMap<String, Object>() {{"
87
+ else
88
+ consts << " public static final String FIELD_#{column_name.upcase} = \"#{column_name}\";"
89
+ fields << " metaData.put(FIELD_#{column_name.upcase}, new HashMap<String, Object>() {{"
90
+ end
91
+
92
+ unless column_data.nil?
93
+
94
+ column_data.each do |key, value|
95
+
96
+ case key.to_s
97
+ when Blufin::YmlSchemaValidator::DESCRIPTION
98
+ handle_description(value)
99
+ when Blufin::YmlSchemaValidator::TYPE
100
+ handle_type(value, schema, table, column_name, column_data)
101
+ when Blufin::YmlSchemaValidator::FLAG
102
+ handle_flag(value)
103
+ when Blufin::YmlSchemaValidator::FKEY
104
+ handle_fkey(value)
105
+ when Blufin::YmlSchemaValidator::REQUIRED
106
+ handle_required(schema, table, value, table_data)
107
+ when Blufin::YmlSchemaValidator::REQUIRED_IF
108
+ handle_required_if(schema, table, value, table_data)
109
+ when Blufin::YmlSchemaValidator::ENCRYPTED
110
+ handle_encrypted(value)
111
+ when Blufin::YmlSchemaValidator::TRANSIENT
112
+ handle_transient(value)
113
+ when Blufin::YmlSchemaValidator::CHILD_OF
114
+ handle_child_of(value)
115
+ when Blufin::YmlSchemaValidator::CHILD_TYPE # For constructor parameter(s).
116
+ handle_child_type(value)
117
+ else
118
+ raise RuntimeError, "Unrecognized column key in #{__FILE__}: #{key}"
119
+ end
120
+
121
+ end
122
+
123
+ end
124
+
125
+ # Handle fields that don't have a 'type' -- IE: Where type is automatically implied.
126
+ handle_type_where_implied(table, column_name)
127
+
128
+ # Check for critical errors...
129
+ raise RuntimeError, "A MetaData field would've rendered without a 'TYPE' \xe2\x86\x92 #{schema}.#{table} \xe2\x86\x92 #{column_name}" if @type.nil?
130
+
131
+ fields << @type unless @type.nil?
132
+ fields << @flag unless @flag.nil?
133
+ fields << @fkey unless @fkey.nil?
134
+ fields << @link unless @link.nil?
135
+ fields << @encrypted unless @encrypted.nil?
136
+ fields << @max_length unless @max_length.nil?
137
+ fields << @transient unless @transient.nil?
138
+ fields << @child_of unless @child_of.nil?
139
+ fields << @description unless @description.nil?
140
+ fields << @required unless @required.nil?
141
+ fields << @required_if unless @required_if.nil?
142
+ fields << @decimal_distribution unless @decimal_distribution.nil?
143
+ fields << @enum_name unless @enum_name.nil?
144
+ fields << @enum_values unless @enum_values.nil?
145
+ fields << " }});\n"
146
+
147
+ end
148
+
149
+ hierarchy_result = extract_hierarchy(schema, table, @schema_resources["#{schema}.#{table}"][:dependents], @schema_resources.keys)
150
+ hierarchy = hierarchy_result[0]
151
+ hierarchy_nested_only = hierarchy_result[1]
152
+
153
+ class_name = "#{Blufin::Strings::snake_case_to_camel_case(table)}#{Blufin::YmlJavaMetaWriter::META_DATA}"
154
+ content = ["package #{get_package(@site, schema, PACKAGE, SERVICE)};", '']
155
+ full_file_path = "#{get_java_path(@site, schema, SERVICE, PACKAGE)}/#{class_name}.java"
156
+
157
+ # Generate the content. Shared method between Embedded and non-embedded writers.
158
+ content = generate_content(content, '', consts, fields, hierarchy, hierarchy_nested_only, schema, table, class_name, @import_statements, @child_type)
159
+
160
+ # Write the file.
161
+ write_file_java(full_file_path, content, schema == Blufin::YmlSchemaValidator::MOCK).gsub(@site_location, '')
162
+
163
+ end
164
+
165
+ end
166
+
167
+ end
168
+
169
+ end
170
+
171
+ end
172
+
173
+ end