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,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
|