blufin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/bf +5 -0
- data/bin/blufin +5 -0
- data/lib/blufin.rb +245 -0
- data/lib/core/code_scanners/common/scanner_common.rb +83 -0
- data/lib/core/code_scanners/common/scanner_java.rb +106 -0
- data/lib/core/code_scanners/scanner_java_embedded_objects.rb +386 -0
- data/lib/core/code_scanners/scanner_java_enums.rb +125 -0
- data/lib/core/code_scanners/scanner_java_source.rb +29 -0
- data/lib/core/code_scanners/scanner_java_tests.rb +157 -0
- data/lib/core/error_handling/schema_error.rb +9 -0
- data/lib/core/error_handling/sql_error.rb +21 -0
- data/lib/core/error_handling/sql_error_handler.rb +149 -0
- data/lib/core/error_handling/yml_error.rb +21 -0
- data/lib/core/error_handling/yml_error_handler.rb +437 -0
- data/lib/core/mysql.rb +347 -0
- data/lib/core/opt.rb +21 -0
- data/lib/core/site/site.rb +26 -0
- data/lib/core/site/site_auth.rb +88 -0
- data/lib/core/site/site_embedded.rb +27 -0
- data/lib/core/site/site_ports.rb +9 -0
- data/lib/core/site/site_resolver.rb +276 -0
- data/lib/core/site/site_services.rb +162 -0
- data/lib/core/site/site_ui.rb +16 -0
- data/lib/core/yml/config/yml_config_validator.rb +219 -0
- data/lib/core/yml/maven/yml_maven_validator.rb +1132 -0
- data/lib/core/yml/resource/yml_resource_validator.rb +154 -0
- data/lib/core/yml/schema/yml_schema_flags.rb +9 -0
- data/lib/core/yml/schema/yml_schema_validator.rb +1850 -0
- data/lib/core/yml/yml_cache_handler.rb +115 -0
- data/lib/core/yml/yml_common.rb +487 -0
- data/lib/core/yml/yml_meta_writer_base.rb +300 -0
- data/lib/core/yml/yml_outputter.rb +307 -0
- data/lib/core/yml/yml_validator_base.rb +630 -0
- data/lib/core/yml_writers/yml_configuration_writer.rb +40 -0
- data/lib/core/yml_writers/yml_java_api_resource_writer.rb +348 -0
- data/lib/core/yml_writers/yml_java_cron_type_writer.rb +113 -0
- data/lib/core/yml_writers/yml_java_css_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_dao_writer.rb +364 -0
- data/lib/core/yml_writers/yml_java_dto_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_embedded_object_writer.rb +968 -0
- data/lib/core/yml_writers/yml_java_enum_writer.rb +161 -0
- data/lib/core/yml_writers/yml_java_js_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_message_type_writer.rb +106 -0
- data/lib/core/yml_writers/yml_java_meta_writer.rb +173 -0
- data/lib/core/yml_writers/yml_java_model_writer.rb +510 -0
- data/lib/core/yml_writers/yml_java_pom_writer.rb +1050 -0
- data/lib/core/yml_writers/yml_java_resource_data_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_sdk_writer.rb +732 -0
- data/lib/core/yml_writers/yml_java_validator_writer.rb +280 -0
- data/lib/core/yml_writers/yml_java_worker_writer.rb +81 -0
- data/lib/core/yml_writers/yml_sql_structure_writer.rb +307 -0
- data/lib/core/yml_writers/yml_sql_template_writer.rb +243 -0
- data/lib/core/yml_writers/yml_vue_service_writer.rb +170 -0
- data/lib/core/yml_writers/yml_writer_base.rb +114 -0
- data/lib/routes/api_list.rb +35 -0
- data/lib/routes/api_meta.rb +59 -0
- data/lib/routes/build.rb +46 -0
- data/lib/routes/create/create_api.rb +35 -0
- data/lib/routes/create/create_ui.rb +84 -0
- data/lib/routes/export.rb +56 -0
- data/lib/routes/generate/generate_api.rb +225 -0
- data/lib/routes/generate/generate_img_favicon.rb +56 -0
- data/lib/routes/generate/generate_img_landing.rb +94 -0
- data/lib/routes/generate/generate_lambda.rb +43 -0
- data/lib/routes/lint.rb +35 -0
- data/lib/routes/mysql_reset.rb +43 -0
- data/lib/routes/release_blufin.rb +351 -0
- data/lib/routes/run.rb +35 -0
- data/lib/version.rb +1 -0
- data/opt/README.MD +2 -0
- data/opt/config/schema.yml +73 -0
- data/opt/config/template.yml +25 -0
- data/opt/sql/data/config/data-client.sql +7 -0
- data/opt/sql/data/config/data-db-configuration-property.sql +47 -0
- data/opt/sql/data/config/data-db-configuration.sql +9 -0
- data/opt/sql/data/config/data-db.sql +175 -0
- data/opt/sql/data/config/data-profile-api.sql +47 -0
- data/opt/sql/data/config/data-profile-cron.sql +0 -0
- data/opt/sql/data/config/data-profile-worker.sql +0 -0
- data/opt/sql/data/config/data-profile.sql +87 -0
- data/opt/sql/data/config/data-project.sql +95 -0
- data/opt/sql/structure/blufin-master-structure-fks.sql +65 -0
- data/opt/sql/structure/blufin-master-structure.sql +97 -0
- data/opt/sql/structure/blufin-mock-structure-fks.sql +38 -0
- data/opt/sql/structure/blufin-mock-structure.sql +98 -0
- data/opt/sql/templates/config/template-client.sql +7 -0
- data/opt/sql/templates/config/template-db-configuration-property.sql +11 -0
- data/opt/sql/templates/config/template-db-configuration.sql +9 -0
- data/opt/sql/templates/config/template-db.sql +21 -0
- data/opt/sql/templates/config/template-profile-api.sql +11 -0
- data/opt/sql/templates/config/template-profile-cron.sql +7 -0
- data/opt/sql/templates/config/template-profile-worker.sql +7 -0
- data/opt/sql/templates/config/template-profile.sql +21 -0
- data/opt/sql/templates/config/template-project.sql +23 -0
- data/opt/yml/api/schema/config/client.yml +14 -0
- data/opt/yml/api/schema/config/db.yml +45 -0
- data/opt/yml/api/schema/config/db_configuration.yml +22 -0
- data/opt/yml/api/schema/config/db_configuration_property.yml +22 -0
- data/opt/yml/api/schema/config/profile.yml +53 -0
- data/opt/yml/api/schema/config/profile_api.yml +22 -0
- data/opt/yml/api/schema/config/profile_cron.yml +14 -0
- data/opt/yml/api/schema/config/profile_worker.yml +14 -0
- data/opt/yml/api/schema/config/project.yml +48 -0
- data/opt/yml/api/schema/mock/mock.yml +99 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum_system.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_linked.yml +43 -0
- data/opt/yml/api/schema/mock/mock_nested_multiple.yml +61 -0
- data/opt/yml/api/schema/mock/mock_nested_single.yml +67 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_deep.yml +32 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_super_deep.yml +17 -0
- metadata +240 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
module Blufin
|
|
2
|
+
|
|
3
|
+
# This class scans embedded objects -> IE: AbstractAccount.
|
|
4
|
+
class ScannerJavaEmbeddedObjects
|
|
5
|
+
|
|
6
|
+
@@data = nil
|
|
7
|
+
|
|
8
|
+
EMBEDDED = 'Embedded'
|
|
9
|
+
EMBEDDED_ANNOTATION = '@Embedded'
|
|
10
|
+
|
|
11
|
+
OBJECT = 'OBJECT'
|
|
12
|
+
OBJECT_LIST = 'OBJECT_LIST'
|
|
13
|
+
OBJECT_LINK = 'OBJECT_LINK'
|
|
14
|
+
|
|
15
|
+
PATH_TO_EMBEDDED = 'blufin-sdk/src/main/java/org/blufin/sdk/embedded'
|
|
16
|
+
|
|
17
|
+
KEY_NESTED_TABLE = 'nested_table'
|
|
18
|
+
KEY_TYPE_JAVA = 'type_java'
|
|
19
|
+
|
|
20
|
+
# @return void
|
|
21
|
+
def initialize(site, error_handler)
|
|
22
|
+
|
|
23
|
+
return unless @@data.nil?
|
|
24
|
+
|
|
25
|
+
@@data = {}
|
|
26
|
+
|
|
27
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
|
28
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
|
29
|
+
@site_path = Blufin::SiteResolver::get_site_location(@site)
|
|
30
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
|
31
|
+
|
|
32
|
+
@error_handler = error_handler
|
|
33
|
+
|
|
34
|
+
object_paths = %W(
|
|
35
|
+
#{Blufin::Config::get_path('Paths', 'BlufinJava')}/#{PATH_TO_EMBEDDED}/dto/#{Blufin::YmlSchemaValidator::CONFIG}
|
|
36
|
+
#{Blufin::Config::get_path('Paths', 'BlufinJava')}/#{PATH_TO_EMBEDDED}/dto/#{Blufin::YmlSchemaValidator::COMMON}
|
|
37
|
+
#{Blufin::Config::get_path('Paths', 'BlufinJava')}/#{PATH_TO_EMBEDDED}/dto/#{Blufin::YmlSchemaValidator::APP})
|
|
38
|
+
|
|
39
|
+
object_paths.each do |object_path|
|
|
40
|
+
|
|
41
|
+
Blufin::Files::get_files_in_dir(object_path).each do |file|
|
|
42
|
+
|
|
43
|
+
file_schema = nil
|
|
44
|
+
file_class = nil
|
|
45
|
+
file_data = {}
|
|
46
|
+
file_line = 0
|
|
47
|
+
file_ref = nil
|
|
48
|
+
file_parts = file.split('/')
|
|
49
|
+
field_data = nil
|
|
50
|
+
annotation_data_found = false
|
|
51
|
+
annotation_ruby_found = false
|
|
52
|
+
previous_was_implements = false
|
|
53
|
+
|
|
54
|
+
Blufin::Files::read_file(file).each do |line|
|
|
55
|
+
|
|
56
|
+
file_line += 1
|
|
57
|
+
type = nil
|
|
58
|
+
field = nil
|
|
59
|
+
line.gsub!("\n", '')
|
|
60
|
+
line.gsub!(/\/\*+.+\*+\//, '')
|
|
61
|
+
line.gsub!(/\/{2,}.+\z/, '')
|
|
62
|
+
line.strip!
|
|
63
|
+
|
|
64
|
+
next if line == ''
|
|
65
|
+
|
|
66
|
+
# Extract Schema.
|
|
67
|
+
if file_schema.nil?
|
|
68
|
+
fs = file.split('/')
|
|
69
|
+
file_schema = fs[fs.length - 2]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
annotation_data_found = true if !annotation_data_found && line =~ /\A@Data\z/
|
|
73
|
+
annotation_ruby_found = true if !annotation_ruby_found && line =~ /\A@ParsedByRuby\z/
|
|
74
|
+
|
|
75
|
+
# Extract Reference (from @Embedded annotation)
|
|
76
|
+
if file_ref.nil? && line =~ /\A@Embedded\("[\S]+"\)\z/
|
|
77
|
+
file_ref = line
|
|
78
|
+
file_ref.gsub!(/\A#{EMBEDDED_ANNOTATION}\("/, '')
|
|
79
|
+
file_ref.gsub!(/"\)\z/, '')
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Extract Class.
|
|
83
|
+
if file_class.nil? && line =~ /\Apublic\s+abstract\s+class/
|
|
84
|
+
file_class = extract_class_name(line)
|
|
85
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_ABSTRACTION, file, nil, nil, file_class)
|
|
86
|
+
add_error_abstract_dto_implementation(line, file, file_class)
|
|
87
|
+
next
|
|
88
|
+
elsif file_class.nil? && line =~ /\Apublic\s+class\s+/
|
|
89
|
+
file_class = extract_class_name(line)
|
|
90
|
+
add_error_abstract_dto_implementation(line, file, file_class)
|
|
91
|
+
next
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Start parsing fields only once class name has been resolved.
|
|
95
|
+
unless file_class.nil?
|
|
96
|
+
|
|
97
|
+
# Extract Data.
|
|
98
|
+
if line =~ /\A@Implements/
|
|
99
|
+
|
|
100
|
+
# @Implements(DataType.INT)
|
|
101
|
+
if line =~ /\A@Implements\(DataType\.[A-Z_]+\)\z/
|
|
102
|
+
|
|
103
|
+
data_type = line.gsub(/\A@Implements\(DataType\./, '').gsub(/\)\z/, '')
|
|
104
|
+
field_data = add_data_type(file, data_type)
|
|
105
|
+
|
|
106
|
+
elsif line =~ /\A@Implements\(value\s=\sDataType\.[A-Z_]+(,\sextra\s=\s"[A-Za-z0-9]+")?(,\sflags\s=\s{[A-Za-z0-9.,_\s]+})?(,\sfkey\s=\s"[a-z_.]+")?(,\sencrypted\s=\s(true|false))?\)\z/
|
|
107
|
+
|
|
108
|
+
# Extract DataType
|
|
109
|
+
data_type = line.gsub(/\A@Implements\(value\s=\sDataType\./, '').gsub(/(,\s(.)+)?\)\z/, '')
|
|
110
|
+
# Extract Extra
|
|
111
|
+
if line =~/,\sextra\s=\s"[A-Za-z0-9]+"/
|
|
112
|
+
extra = line.split('extra = "')
|
|
113
|
+
extra = extra[1].gsub(/"(,\s(.)+)?\)\z/, '')
|
|
114
|
+
else
|
|
115
|
+
extra = nil
|
|
116
|
+
end
|
|
117
|
+
field_data = add_data_type(file, data_type, extra)
|
|
118
|
+
# Extract Flags
|
|
119
|
+
if line =~/,\sflags\s=\s{[A-Za-z0-9.,_\s]+}/
|
|
120
|
+
flags = line.gsub(/\A(.)+flags\s=\s{/, '').gsub(/}(,\s*.+)?\)\z/, '')
|
|
121
|
+
# Adjust AUTO_INCREMENT flag with value (if necessary).
|
|
122
|
+
flags = flags.gsub(Blufin::YmlSchemaValidator::FLAG_AUTO_INCREMENT, "#{Blufin::YmlSchemaValidator::FLAG_AUTO_INCREMENT}(#{extra})") if data_type == 'INT_AUTO' && extra.to_i > 0
|
|
123
|
+
flags = flags.split(/\s?,\s?/)
|
|
124
|
+
flags = flags.map { |n| n.gsub(/\ADataTypeFlag\./, '') }
|
|
125
|
+
field_data = field_data.merge({ :flag => flags })
|
|
126
|
+
end
|
|
127
|
+
# Extract Fkey
|
|
128
|
+
if line =~/,\sfkey\s=\s"[a-z_.]+"/
|
|
129
|
+
fkey = line.gsub(/\A(.)+fkey\s=\s"/, '').gsub(/"(.)+\z/, '')
|
|
130
|
+
field_data = field_data.merge({ :fkey => "#{file_schema}.#{fkey}" })
|
|
131
|
+
end
|
|
132
|
+
# Extract Encrypted
|
|
133
|
+
if line =~/,\sencrypted\s=\s(true|false)/
|
|
134
|
+
encrypted = line.gsub(/\A(.)+encrypted\s=\s/, '').gsub(/e(.)+\z/, '')
|
|
135
|
+
encrypted ="#{encrypted}e"
|
|
136
|
+
field_data = field_data.merge({ :encrypted => encrypted })
|
|
137
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_ANNOTATION_UNNECESSARY, file, nil, nil, 'encrypted = false') if encrypted == 'false'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
elsif line =~ /\A@ImplementsObject\(value\s=\s"[a-z_]+",\srelation\s=\sRelation\.(ONE_TO_ONE|ONE_TO_MANY|MANY_TO_MANY)\)\z/
|
|
141
|
+
|
|
142
|
+
data_type = line.gsub(/\A@ImplementsObject\(value\s=\s"[a-z_]+",\srelation\s=\sRelation\./, '').gsub(/\)\z/, '')
|
|
143
|
+
case data_type
|
|
144
|
+
when 'ONE_TO_ONE'
|
|
145
|
+
data_type = OBJECT
|
|
146
|
+
nested_table = line.gsub(/\A@ImplementsObject\(value\s=\s"/, '').gsub(/"(.)+\z/, '')
|
|
147
|
+
when 'ONE_TO_MANY'
|
|
148
|
+
data_type = OBJECT_LIST
|
|
149
|
+
nested_table = line.gsub(/\A@ImplementsObject\(value\s=\s"/, '').gsub(/"(.)+\z/, '')
|
|
150
|
+
when 'MANY_TO_MANY'
|
|
151
|
+
data_type = OBJECT_LINK
|
|
152
|
+
|
|
153
|
+
# TODO - FINISH once OBJECT_LINK needs to be supported.
|
|
154
|
+
raise RuntimeError, "#{OBJECT_LINK} not yet supported for @Embedded Objects."
|
|
155
|
+
|
|
156
|
+
else
|
|
157
|
+
raise RuntimeError, "Unrecognized data-type: #{data_type}"
|
|
158
|
+
end
|
|
159
|
+
field_data = { :type => data_type, :nested_table => "#{file_schema}.#{nested_table}" }
|
|
160
|
+
|
|
161
|
+
else
|
|
162
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_LINE, file, nil, nil, "#{file_line.to_s.rjust(2)}: #{line}")
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
previous_was_implements = true
|
|
166
|
+
|
|
167
|
+
elsif previous_was_implements && line =~ /\Aprivate\s+(List<)?[A-Za-z0-9_]+(>)?\s+[A-Za-z0-9_]+;\z/
|
|
168
|
+
|
|
169
|
+
next if field_data.inspect == '{}'
|
|
170
|
+
|
|
171
|
+
line_split = line.gsub(/\A(private)\s+/, '').split(' ')
|
|
172
|
+
type_java = line_split[0]
|
|
173
|
+
field = line_split[line_split.length - 1].gsub(/;\z/, '')
|
|
174
|
+
field = Blufin::Strings::camel_case_to_snake_case(field).gsub(/>/, '')
|
|
175
|
+
|
|
176
|
+
raise RuntimeError, "Expected :type key to exist for field: #{field}, instead got: #{field_data.inspect}" if field_data[:type].nil?
|
|
177
|
+
|
|
178
|
+
field_data[:type_java] = type_java
|
|
179
|
+
|
|
180
|
+
type = field_data[:type]
|
|
181
|
+
|
|
182
|
+
# Throw error if field is encrypted and config (schema).
|
|
183
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_CONFIG_CANNOT_BE_ENCRYPTED, file, nil, nil, field) if field_data[:encrypted] && file_schema == Blufin::YmlSchemaValidator::CONFIG
|
|
184
|
+
|
|
185
|
+
if type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
|
186
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['Boolean', type_java]) unless type_java == 'Boolean'
|
|
187
|
+
elsif [
|
|
188
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME,
|
|
189
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT,
|
|
190
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_UPDATE
|
|
191
|
+
].include?(type)
|
|
192
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['ZonedDateTime', type_java]) unless type_java == 'ZonedDateTime'
|
|
193
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_DATE
|
|
194
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['LocalDate', type_java]) unless type_java == 'LocalDate'
|
|
195
|
+
elsif type =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL
|
|
196
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['BigDecimal', type_java]) unless type_java == 'BigDecimal'
|
|
197
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_INT_TINY
|
|
198
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['Byte', type_java]) unless type_java == 'Byte'
|
|
199
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
|
|
200
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['Short', type_java]) unless type_java == 'Short'
|
|
201
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_INT_BIG
|
|
202
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['Long', type_java]) unless type_java == 'Long'
|
|
203
|
+
elsif [
|
|
204
|
+
Blufin::YmlSchemaValidator::TYPE_INT,
|
|
205
|
+
Blufin::YmlSchemaValidator::TYPE_INT_AUTO
|
|
206
|
+
].include?(type)
|
|
207
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['Integer', type_java]) unless type_java == 'Integer'
|
|
208
|
+
elsif [
|
|
209
|
+
Blufin::YmlSchemaValidator::TYPE_TEXT,
|
|
210
|
+
Blufin::YmlSchemaValidator::TYPE_TEXT_LONG
|
|
211
|
+
].include?(type)
|
|
212
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['String', type_java]) unless type_java == 'String'
|
|
213
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_ENUM
|
|
214
|
+
raise RuntimeError, 'ENUM should never be used with @Embedded objects. Only use ENUM_SYSTEM because enums need to be shared across apps.'
|
|
215
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_ENUM_CUSTOM
|
|
216
|
+
raise RuntimeError, 'ENUM_CUSTOM should never be used with @Embedded objects. Only use ENUM_SYSTEM because enums need to be shared across apps.'
|
|
217
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_ENUM_SYSTEM
|
|
218
|
+
# Do nothing.
|
|
219
|
+
elsif type =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
|
|
220
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_DATA_TYPE_INVALID, file, nil, nil, ['String', type_java]) unless type_java == 'String'
|
|
221
|
+
elsif type == OBJECT
|
|
222
|
+
# Do nothing.
|
|
223
|
+
elsif type == OBJECT_LIST
|
|
224
|
+
object_list_regex = /\A[a-z_]+list\z/
|
|
225
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_REGEX, file, nil, nil, [field, Blufin::YmlCommon::convert_regex_to_string(object_list_regex)]) unless field =~ object_list_regex
|
|
226
|
+
field = field.gsub(/_list\z/, '')
|
|
227
|
+
elsif type == OBJECT_LINK
|
|
228
|
+
|
|
229
|
+
# TODO - FINISH once OBJECT_LINK need to be supported.
|
|
230
|
+
raise RuntimeError, 'OBJECT_LINK is not currently supported by @Embedded objects.'
|
|
231
|
+
|
|
232
|
+
else
|
|
233
|
+
raise RuntimeError, "Unrecognized type in #{__FILE__}: #{type}"
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
file_data[field] = field_data
|
|
237
|
+
field_data = {}
|
|
238
|
+
|
|
239
|
+
else
|
|
240
|
+
|
|
241
|
+
previous_was_implements = false
|
|
242
|
+
|
|
243
|
+
next if line == '}'
|
|
244
|
+
next if line =~ /\/\*\*/
|
|
245
|
+
next if line =~ /\*\//
|
|
246
|
+
next if line =~ /@Override/
|
|
247
|
+
next if line =~ /@JsonIgnore/
|
|
248
|
+
next if line =~ /public\sInteger\sgetParentId\(\)\s{/
|
|
249
|
+
next if line =~ /return\sget[A-Za-z]+\(\);/
|
|
250
|
+
|
|
251
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_LINE, file, nil, nil, "#{file_line.to_s.rjust(2)}: #{line}")
|
|
252
|
+
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Make sure we have a valid schema (defined through annotation) and that it's not nil.
|
|
260
|
+
unless file_schema.to_s =~ /(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})/
|
|
261
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_SCHEMA, file, nil, nil, file_schema)
|
|
262
|
+
next
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# Make sure that the file reference matches the same REGEX that schema tables would be (IE: lowercase & snake-case).
|
|
266
|
+
if file_ref.nil?
|
|
267
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_NO_ANNOTATION, file, nil, nil, nil)
|
|
268
|
+
next
|
|
269
|
+
elsif file_ref !~ /\A[a-z_]+\z/
|
|
270
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_REF_REGEX, file, nil, nil, file_ref)
|
|
271
|
+
elsif file_ref.length > Blufin::YmlSchemaValidator::MAX_TABLE_CHARACTERS
|
|
272
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_REF_LENGTH, file, nil, nil, file_ref)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
# Make sure class starts with the word "Embedded" (and is not nil).
|
|
276
|
+
if file_class.nil? || !(file_class =~ /#{EMBEDDED}[A-Za-z]/)
|
|
277
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_NAME, file, nil, nil, file_class)
|
|
278
|
+
next
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
# Make sure we've found some fields (at least 1).
|
|
282
|
+
if file_data.nil?
|
|
283
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_DATA_NOT_FOUND, file, nil, nil, file_class)
|
|
284
|
+
next
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
@@data[file_ref] = {
|
|
288
|
+
:schema => file_schema,
|
|
289
|
+
:table => file_ref,
|
|
290
|
+
:class => file_class.gsub(/\A#{EMBEDDED}/, ''),
|
|
291
|
+
:data => file_data
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
# Make sure we have correct annotations.
|
|
295
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_ANNOTATION_MISSING, file, nil, nil, '@Data') unless annotation_data_found
|
|
296
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_ANNOTATION_MISSING, file, nil, nil, '@ParsedByRuby') unless annotation_ruby_found
|
|
297
|
+
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Add Dependents.
|
|
303
|
+
@@data.each do |key, value|
|
|
304
|
+
hierarchy = []
|
|
305
|
+
hierarchy = extract_hierarchy(key, hierarchy)
|
|
306
|
+
@@data[key][:dependents] = hierarchy
|
|
307
|
+
if hierarchy.any?
|
|
308
|
+
data = value[:data]
|
|
309
|
+
schema = value[:schema]
|
|
310
|
+
table = value[:table]
|
|
311
|
+
if data.is_a?(Hash) && data.any?
|
|
312
|
+
data.each do |key_inner, value_inner|
|
|
313
|
+
type = value_inner[:type]
|
|
314
|
+
table_nested = value_inner[:nested_table]
|
|
315
|
+
if [Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT, Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST].include?(type)
|
|
316
|
+
child_key = "#{table}_#{Blufin::YmlSchemaValidator::ID}"
|
|
317
|
+
child_object = @@data[table_nested.split('.')[1]][:data][child_key]
|
|
318
|
+
raise RuntimeError, "Expected #{table_nested}.#{child_key} to have :fkey, instead got: #{child_object}" unless child_object.has_key?(:fkey)
|
|
319
|
+
@@data[table_nested.split('.')[1]][:data][child_key] = child_object.merge({ :child_of => "#{table}", :child_type => "DataType.#{type}"})
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# Returns data Hash.
|
|
328
|
+
# @return Hash
|
|
329
|
+
def get_data
|
|
330
|
+
@@data
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
private
|
|
334
|
+
|
|
335
|
+
# Used to recursively loop through @@data to find nested objects.
|
|
336
|
+
# @return ?
|
|
337
|
+
def extract_hierarchy(prefix, hierarchy)
|
|
338
|
+
@@data.each do |key, value|
|
|
339
|
+
unless value[:data].nil?
|
|
340
|
+
value[:data].each do |field, field_data|
|
|
341
|
+
unless field_data[:nested_table].nil?
|
|
342
|
+
if field =~ /\A#{prefix}_[a-z]+\z/
|
|
343
|
+
hierarchy << field
|
|
344
|
+
extract_hierarchy(field, hierarchy)
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
hierarchy
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# Extracts class name from a file line.
|
|
354
|
+
# @return String
|
|
355
|
+
def extract_class_name(line)
|
|
356
|
+
line.gsub(/\Apublic\s+(abstract)?\s?class\s?/, '').split(' ')[0]
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# Adds an error if class does not implement PersistentDto.
|
|
360
|
+
# @return void
|
|
361
|
+
def add_error_abstract_dto_implementation(line, file, class_name)
|
|
362
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_OBJECT_INVALID_EXTENSION, file, nil, nil, class_name) unless line =~ /extends\s+PersistentDtoEmbedded\s+{\z/
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# Adds a data type.
|
|
366
|
+
# @return Hash
|
|
367
|
+
def add_data_type(file, data_type, extra = nil)
|
|
368
|
+
|
|
369
|
+
converted_data_type = data_type
|
|
370
|
+
|
|
371
|
+
# Validate the EXTRA data.
|
|
372
|
+
if converted_data_type == 'VARCHAR' && !extra.nil?
|
|
373
|
+
if extra.to_i > 0
|
|
374
|
+
converted_data_type = "VARCHAR(#{extra})"
|
|
375
|
+
else
|
|
376
|
+
@error_handler.add_error(Blufin::YmlErrorHandler::EMBEDDED_EXTRA_VALUE_INVALID, file, nil, nil, ['Integer (> 0)', extra.to_s])
|
|
377
|
+
return {}
|
|
378
|
+
end
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
{ :type => converted_data_type }
|
|
382
|
+
end
|
|
383
|
+
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
end
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
module Blufin
|
|
2
|
+
|
|
3
|
+
class ScannerJavaEnums
|
|
4
|
+
|
|
5
|
+
@@enum_scanned = false
|
|
6
|
+
@@enum_auto = nil
|
|
7
|
+
@@enum_custom = nil
|
|
8
|
+
@@enum_system = nil
|
|
9
|
+
|
|
10
|
+
# Read all enum values into class variable -- shard between instances meaning re-instantiating the class won't require re-scanning enums.
|
|
11
|
+
# @return void
|
|
12
|
+
def initialize(site)
|
|
13
|
+
|
|
14
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
|
15
|
+
|
|
16
|
+
unless @@enum_scanned
|
|
17
|
+
|
|
18
|
+
directories = %W(
|
|
19
|
+
#{Blufin::SiteResolver::path_to_java_sdk_core(@site)}/src/main/java/#{Blufin::SiteResolver::get_site_domain(@site)}/#{Blufin::SiteResolver::get_site_name(@site)}/sdk/enums
|
|
20
|
+
#{Blufin::SiteResolver::path_to_blufin_java}/blufin-base/src/main/java/#{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS.gsub('.', '/')}
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
directories.each_with_index do |directory_data, idx|
|
|
24
|
+
|
|
25
|
+
hash = {}
|
|
26
|
+
hash_nested = {}
|
|
27
|
+
|
|
28
|
+
if Blufin::Files::path_exists(directory_data)
|
|
29
|
+
|
|
30
|
+
Blufin::Files::get_files_in_dir(directory_data).each do |file|
|
|
31
|
+
|
|
32
|
+
enum_title = nil
|
|
33
|
+
enum_exists = false
|
|
34
|
+
|
|
35
|
+
Blufin::Files::read_file(file).each do |line|
|
|
36
|
+
|
|
37
|
+
# If line matches "public enum XXX {"
|
|
38
|
+
if enum_exists == false && line.strip =~ /public\s+enum\s+[A-Za-z0-9]+\s*\{/
|
|
39
|
+
enum_exists = true
|
|
40
|
+
enum_title = line.strip.gsub(/public\s+enum\s+/, '').gsub(/\s*\{/, '')
|
|
41
|
+
hash[enum_title] = []
|
|
42
|
+
hash_nested[enum_title] = (file.gsub(directory_data, '').gsub(/\A\//, '').split('/').length > 1) ? true : false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Extract ENUM values and put them inside @enum hash.
|
|
46
|
+
if enum_exists
|
|
47
|
+
|
|
48
|
+
if line.strip =~ /\A[A-Z_]+(\(.*\))*(,|;|)\z/
|
|
49
|
+
matcher = line.strip.match(/\A[A-Z_]+/)
|
|
50
|
+
hash[enum_title] << matcher[0]
|
|
51
|
+
elsif line.strip =~ /\A[A-Z_,\s]+(,|;|)\z/
|
|
52
|
+
line.strip.split(',').each do |value|
|
|
53
|
+
hash[enum_title] << value.strip
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
if idx == 0
|
|
66
|
+
|
|
67
|
+
@@enum_auto = {}
|
|
68
|
+
@@enum_custom = {}
|
|
69
|
+
|
|
70
|
+
hash.each do |key, value|
|
|
71
|
+
if hash_nested[key]
|
|
72
|
+
@@enum_auto[key] = value
|
|
73
|
+
else
|
|
74
|
+
@@enum_custom[key] = value
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
elsif idx == 1
|
|
79
|
+
@@enum_system = hash
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
@@enum_scanned = true
|
|
85
|
+
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Returns CUSTOM enum values as Array.
|
|
91
|
+
# @return Array
|
|
92
|
+
def get_enum_custom_values_for(enum_name)
|
|
93
|
+
raise RuntimeError, "#{enum_name} has not been found to be a CUSTOM_ENUM" unless @@enum_custom.has_key?(enum_name)
|
|
94
|
+
@@enum_custom[enum_name]
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Returns SYSTEM enum values as Array.
|
|
99
|
+
# @return Array
|
|
100
|
+
def get_enum_system_values_for(enum_name)
|
|
101
|
+
raise RuntimeError, "#{enum_name} has not been found to be a SYSTEM_ENUM" unless @@enum_system.has_key?(enum_name)
|
|
102
|
+
@@enum_system[enum_name]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Returns a Hash with all of the Auto-generated ENUM data.
|
|
106
|
+
# @return Hash
|
|
107
|
+
def get_auto_enums
|
|
108
|
+
@@enum_auto
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Returns a Hash with all of the Custom ENUM data.
|
|
112
|
+
# @return Hash
|
|
113
|
+
def get_custom_enums
|
|
114
|
+
@@enum_custom
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Returns a Hash with all of the System ENUM data.
|
|
118
|
+
# @return Hash
|
|
119
|
+
def get_system_enums
|
|
120
|
+
@@enum_system
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|