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,280 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlJavaValidatorWriter < Blufin::YmlWriterBase
|
4
|
+
|
5
|
+
SERVICE = Blufin::SiteServices::API
|
6
|
+
PACKAGE = "#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.validator"
|
7
|
+
|
8
|
+
PLACEHOLDER_SITE_NAME = '{{--SITE-NAME--}}'
|
9
|
+
PLACEHOLDER_SITE_DOMAIN = '{{--SITE-DOMAIN--}}'
|
10
|
+
PLACEHOLDER_OBJECT = '{{--OBJECT--}}'
|
11
|
+
PLACEHOLDER_OBJECT_LOWERCASE = '{{--OBJECT-LOWERCASE--}}'
|
12
|
+
PLACEHOLDER_VALIDATE_SWITCH = '{{--VALIDATE-SWITCH--}}'
|
13
|
+
|
14
|
+
# @return void
|
15
|
+
def initialize(site, schema_data, schema_resources)
|
16
|
+
|
17
|
+
@schema_data = schema_data
|
18
|
+
@schema_resources = schema_resources
|
19
|
+
|
20
|
+
raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
|
21
|
+
raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash)
|
22
|
+
|
23
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
24
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
25
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
26
|
+
@site_domain_gsub = @site_domain.strip == '' ? '' : "#{@site_domain}."
|
27
|
+
@site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
|
28
|
+
|
29
|
+
# Wipe out all previous files.
|
30
|
+
Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
|
31
|
+
path_to_wipe_out = "#{get_java_path(@site, schema, SERVICE, PACKAGE)}"
|
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
|
+
|
39
|
+
@template = <<TEMPLATE
|
40
|
+
package #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.#{Blufin::SiteServices::API}.#{PACKAGE};
|
41
|
+
|
42
|
+
import org.blufin.api.base.AbstractValidator;
|
43
|
+
import org.blufin.sdk.rest.PatchOperation;
|
44
|
+
import org.blufin.base.annotations.AutoGenerated;
|
45
|
+
import org.blufin.base.annotations.Singleton;
|
46
|
+
import org.blufin.base.annotations.TestNotRequired;
|
47
|
+
import org.blufin.base.annotations.helper.ON;
|
48
|
+
import org.blufin.base.exceptions.BlufinAlertDeveloperException;
|
49
|
+
import org.blufin.base.exceptions.BlufinServerException;
|
50
|
+
import org.blufin.base.enums.Environment;
|
51
|
+
import org.blufin.sdk.base.PersistentDto;
|
52
|
+
import org.blufin.sdk.enums.PayloadType;
|
53
|
+
import org.blufin.sdk.response.AckError;
|
54
|
+
import org.blufin.sdk.response.AckResolver;
|
55
|
+
import java.util.List;
|
56
|
+
import java.sql.Connection;
|
57
|
+
import java.text.MessageFormat;
|
58
|
+
import org.springframework.stereotype.Service;
|
59
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.api.#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.dao.#{PLACEHOLDER_OBJECT}Dao;
|
60
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.metadata.#{PLACEHOLDER_OBJECT}MetaData;
|
61
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{PLACEHOLDER_OBJECT};
|
62
|
+
import lombok.Getter;#{PLACEHOLDER_IMPORT}
|
63
|
+
|
64
|
+
@Service
|
65
|
+
public class #{PLACEHOLDER_OBJECT}Validator extends AbstractValidator<#{PLACEHOLDER_OBJECT}> {
|
66
|
+
|
67
|
+
@Getter
|
68
|
+
private static final #{PLACEHOLDER_OBJECT}Validator instance = new #{PLACEHOLDER_OBJECT}Validator();
|
69
|
+
|
70
|
+
@Singleton
|
71
|
+
private #{PLACEHOLDER_OBJECT}Validator() {
|
72
|
+
|
73
|
+
super(#{PLACEHOLDER_OBJECT}Dao.getInstance(), #{PLACEHOLDER_OBJECT}MetaData.getInstance());
|
74
|
+
}
|
75
|
+
|
76
|
+
@Override
|
77
|
+
protected <T extends PersistentDto> void validate(Connection connection, #{PLACEHOLDER_OBJECT} #{PLACEHOLDER_OBJECT_LOWERCASE}, T parent, AckResolver ackResolver, String tree, String fieldName, Integer idx, PayloadType payloadType) throws BlufinServerException {
|
78
|
+
|
79
|
+
switch (fieldName) {
|
80
|
+
#{PLACEHOLDER_VALIDATE_SWITCH}
|
81
|
+
default:
|
82
|
+
throw new BlufinAlertDeveloperException(MessageFormat.format("Unrecognized field-name: {0}", getTree(tree, fieldName, idx)));
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
TEMPLATE
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
# @return void
|
91
|
+
def write
|
92
|
+
|
93
|
+
@schema_data.each do |schema, schema_data|
|
94
|
+
|
95
|
+
schema_data.each_with_index do |(table, table_data), idx|
|
96
|
+
|
97
|
+
if table_data.is_a?(Hash) && table_data.length > 0
|
98
|
+
|
99
|
+
import_statements = []
|
100
|
+
|
101
|
+
@validate_switch = {}
|
102
|
+
|
103
|
+
@letter_idx = 7
|
104
|
+
|
105
|
+
table_data.each do |column_name, column_data|
|
106
|
+
|
107
|
+
# Skip ID. They way this is handled will be har-coded into the template.
|
108
|
+
next if column_name =~ /\Aid\z/i
|
109
|
+
|
110
|
+
# Handle Placeholders
|
111
|
+
if column_name =~ /^(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+$/ || column_name =~ /^(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]$/
|
112
|
+
|
113
|
+
list_type = column_data.has_key?(Blufin::YmlSchemaValidator::TYPE) && column_data[Blufin::YmlSchemaValidator::TYPE] == Blufin::ScannerJavaEmbeddedObjects::OBJECT_LIST
|
114
|
+
|
115
|
+
column_name_dup = column_name.dup.gsub('[]', '').split('.')[1]
|
116
|
+
column_name_upcase = column_name_dup.upcase
|
117
|
+
column_name_camel_case = "#{Blufin::Strings::snake_case_to_camel_case(column_name_dup)}"
|
118
|
+
column_name_key = list_type ? "#{column_name_upcase}_LIST" : column_name_upcase
|
119
|
+
|
120
|
+
@validate_switch[column_name_key] = []
|
121
|
+
|
122
|
+
if column_data.is_a?(Hash)
|
123
|
+
@required = (column_data.has_key?(Blufin::YmlSchemaValidator::REQUIRED) && column_data[Blufin::YmlSchemaValidator::REQUIRED] == true) || column_data.has_key?(Blufin::YmlSchemaValidator::REQUIRED_IF)
|
124
|
+
@required_if = column_data.has_key?(Blufin::YmlSchemaValidator::REQUIRED_IF) ? column_data[Blufin::YmlSchemaValidator::REQUIRED_IF] : nil
|
125
|
+
else
|
126
|
+
@required = false # Will always be a BOOLEAN
|
127
|
+
@required_if = nil # Will always be a String (IE: 'originating_platform=MAGENTO') or nil.
|
128
|
+
end
|
129
|
+
|
130
|
+
if list_type
|
131
|
+
import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{column_name_camel_case};"
|
132
|
+
import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.metadata.#{column_name_camel_case}MetaData;"
|
133
|
+
@validate_switch[column_name_key] << " validateList(connection, #{PLACEHOLDER_OBJECT_LOWERCASE}.get#{column_name_camel_case}List(), #{PLACEHOLDER_OBJECT_LOWERCASE}, ackResolver, tree, fieldName, idx, #{column_name_camel_case}Validator.getInstance(), payloadType);"
|
134
|
+
else
|
135
|
+
if !@required_if.nil?
|
136
|
+
value_split = @required_if.split('=')
|
137
|
+
enum_field = value_split[0]
|
138
|
+
enum_value = value_split[1]
|
139
|
+
enum_data = @schema_data[schema][table][enum_field][Blufin::YmlSchemaValidator::TYPE]
|
140
|
+
enum_type = Blufin::YmlCommon::enum_type_extractor(enum_data)
|
141
|
+
case enum_type
|
142
|
+
when Blufin::YmlSchemaValidator::TYPE_ENUM
|
143
|
+
required_enum_name = "#{PLACEHOLDER_OBJECT}#{Blufin::Strings::snake_case_to_camel_case(enum_field)}"
|
144
|
+
required_enum_value = "#{required_enum_name}.#{enum_value}"
|
145
|
+
import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.enums.#{required_enum_name};"
|
146
|
+
when Blufin::YmlSchemaValidator::TYPE_ENUM_CUSTOM
|
147
|
+
required_enum_name = enum_data.gsub(/\A#{Blufin::YmlSchemaValidator::TYPE_ENUM_CUSTOM}\(/, '').gsub(/\)\z/, '').gsub(/\A'/, '').gsub(/'\z/, '')
|
148
|
+
required_enum_value = "#{required_enum_name}.#{enum_value}"
|
149
|
+
import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.enums.#{required_enum_name};"
|
150
|
+
when Blufin::YmlSchemaValidator::TYPE_ENUM_SYSTEM
|
151
|
+
required_enum_name = enum_data.gsub(/\A#{Blufin::YmlSchemaValidator::TYPE_ENUM_SYSTEM}\(/, '').gsub(/\)\z/, '').gsub(/\A'/, '').gsub(/'\z/, '')
|
152
|
+
required_enum_value = "#{required_enum_name}.#{enum_value}"
|
153
|
+
import_statements << "import #{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS}.#{required_enum_name};"
|
154
|
+
else
|
155
|
+
raise RuntimeError, "Unrecognized enum_type in #{__FILE__}: #{enum_type}"
|
156
|
+
end
|
157
|
+
@validate_switch[column_name_key] << " validateObjectConditionally(connection, #{PLACEHOLDER_OBJECT_LOWERCASE}.get#{column_name_camel_case}(), #{PLACEHOLDER_OBJECT_LOWERCASE}, ackResolver, tree, fieldName, idx, #{column_name_camel_case}Validator.getInstance(), payloadType, #{PLACEHOLDER_OBJECT}MetaData.FIELD_#{enum_field.upcase}, #{required_enum_value}, #{PLACEHOLDER_OBJECT_LOWERCASE}.get#{Blufin::Strings::snake_case_to_camel_case(enum_field)}());"
|
158
|
+
elsif @required
|
159
|
+
@validate_switch[column_name_key] << " assertNotNull(#{PLACEHOLDER_OBJECT_LOWERCASE}.get#{column_name_camel_case}(), ackResolver, tree, fieldName, idx);"
|
160
|
+
@validate_switch[column_name_key] << " validateObject(connection, #{PLACEHOLDER_OBJECT_LOWERCASE}.get#{column_name_camel_case}(), #{PLACEHOLDER_OBJECT_LOWERCASE}, ackResolver, tree, fieldName, idx, #{column_name_camel_case}Validator.getInstance(), payloadType);"
|
161
|
+
else
|
162
|
+
@validate_switch[column_name_key] << " validateObject(connection, #{PLACEHOLDER_OBJECT_LOWERCASE}.get#{column_name_camel_case}(), #{PLACEHOLDER_OBJECT_LOWERCASE}, ackResolver, tree, fieldName, idx, #{column_name_camel_case}Validator.getInstance(), payloadType);"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
next
|
166
|
+
elsif column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
|
167
|
+
column_name_dup = column_name.dup.gsub("[#{Blufin::YmlSchemaValidator::LINK}]", '').split('.')[1]
|
168
|
+
column_name_upcase = column_name_dup.upcase
|
169
|
+
column_name_key = "#{column_name_upcase}_LIST"
|
170
|
+
@validate_switch[column_name_key] = []
|
171
|
+
|
172
|
+
# TODO - FINISH THIS.
|
173
|
+
|
174
|
+
next
|
175
|
+
else
|
176
|
+
column_name_upcase = column_name.upcase
|
177
|
+
column_name_camel_case = "#{Blufin::Strings::snake_case_to_camel_case(column_name.dup)}"
|
178
|
+
@validate_switch[column_name_upcase] = []
|
179
|
+
end
|
180
|
+
|
181
|
+
field_camel_case = Blufin::Strings.snake_case_to_camel_case(column_name.dup)
|
182
|
+
|
183
|
+
@type = column_data[Blufin::YmlSchemaValidator::TYPE]
|
184
|
+
@is_nullable = column_data.has_key?(Blufin::YmlSchemaValidator::FLAG) && column_data[Blufin::YmlSchemaValidator::FLAG].split(' ').include?(Blufin::YmlSchemaValidator::FLAG_NULLABLE)
|
185
|
+
@is_child = column_data.has_key?(Blufin::YmlSchemaValidator::CHILD_OF) && column_data.has_key?(Blufin::YmlSchemaValidator::CHILD_TYPE)
|
186
|
+
@is_fkey = column_data.has_key?(Blufin::YmlSchemaValidator::FKEY)
|
187
|
+
@is_transient = [Blufin::ScannerJavaEmbeddedObjects::OBJECT].include?(@type) && !column_data[Blufin::YmlSchemaValidator::TRANSIENT].nil?
|
188
|
+
|
189
|
+
# Null-checks.
|
190
|
+
unless @is_nullable || @is_child || @is_transient || [
|
191
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT,
|
192
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_UPDATE
|
193
|
+
].include?(@type)
|
194
|
+
if @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM || @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM || @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
195
|
+
@validate_switch[column_name_upcase] << " assertNotNull(#{PLACEHOLDER_OBJECT_LOWERCASE}.get#{field_camel_case}(), ackResolver, tree, fieldName, idx, true);"
|
196
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
197
|
+
@validate_switch[column_name_upcase] << " assertNotNull(#{PLACEHOLDER_OBJECT_LOWERCASE}.is#{field_camel_case}(), ackResolver, tree, fieldName, idx);"
|
198
|
+
else
|
199
|
+
@validate_switch[column_name_upcase] << " assertNotNull(#{PLACEHOLDER_OBJECT_LOWERCASE}.get#{field_camel_case}(), ackResolver, tree, fieldName, idx);"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# All the different types (and their logic).
|
204
|
+
if @type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
205
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_DATETIME
|
206
|
+
elsif [
|
207
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT,
|
208
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_UPDATE
|
209
|
+
].include?(@type)
|
210
|
+
@validate_switch[column_name_upcase] << " assertNull(#{PLACEHOLDER_OBJECT_LOWERCASE}.get#{field_camel_case}(), ackResolver, tree, fieldName, idx);"
|
211
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_DATE
|
212
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL
|
213
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_TINY
|
214
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
|
215
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_BIG
|
216
|
+
elsif [Blufin::YmlSchemaValidator::TYPE_INT, Blufin::YmlSchemaValidator::TYPE_INT_AUTO].include?(@type)
|
217
|
+
unless @is_child
|
218
|
+
if @is_fkey
|
219
|
+
target_object = Blufin::Strings::snake_case_to_camel_case(column_data[Blufin::YmlSchemaValidator::FKEY].split('.')[1])
|
220
|
+
import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.api.#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.dao.#{target_object}Dao;"
|
221
|
+
import_statements << "import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.metadata.#{target_object}MetaData;"
|
222
|
+
@validate_switch[column_name_upcase] << " assertExists(connection, #{PLACEHOLDER_OBJECT_LOWERCASE}.get#{column_name_camel_case}(), ackResolver, tree, fieldName, idx, #{target_object}MetaData.getInstance(), #{target_object}Dao.getInstance());"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
elsif [Blufin::YmlSchemaValidator::TYPE_TEXT, Blufin::YmlSchemaValidator::TYPE_TEXT_LONG].include?(@type)
|
226
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
227
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM
|
228
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
229
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
|
230
|
+
@validate_switch[column_name_upcase] << " #{PLACEHOLDER_OBJECT_LOWERCASE}.set#{field_camel_case}(normalizeString(#{PLACEHOLDER_OBJECT_LOWERCASE}.get#{field_camel_case}(), ackResolver, tree, fieldName, idx, #{Blufin::YmlCommon::varchar_extract_max_length(column_data[Blufin::YmlSchemaValidator::TYPE])}));"
|
231
|
+
elsif @type == Blufin::ScannerJavaEmbeddedObjects::OBJECT
|
232
|
+
@validate_switch[column_name_upcase] << " assertNull(#{PLACEHOLDER_OBJECT_LOWERCASE}.get#{field_camel_case}(), ackResolver, tree, fieldName, idx);" if @is_transient
|
233
|
+
else
|
234
|
+
raise RuntimeError, "Unrecognized type in #{__FILE__}: #{@type}"
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
import_statements.uniq!
|
240
|
+
import_statements.sort!
|
241
|
+
|
242
|
+
contents = @template
|
243
|
+
|
244
|
+
object = Blufin::Strings::snake_case_to_camel_case(table)
|
245
|
+
object_lower = Blufin::Strings::snake_case_to_camel_case_lower(table)
|
246
|
+
|
247
|
+
contents = contents.gsub(PLACEHOLDER_IMPORT, import_statements.any? ? "\n#{import_statements.join("\n")}" : '')
|
248
|
+
contents = contents.gsub(PLACEHOLDER_VALIDATE_SWITCH, build_switch.join("\n"))
|
249
|
+
|
250
|
+
contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
|
251
|
+
contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
|
252
|
+
contents = contents.gsub(PLACEHOLDER_SCHEMA, schema)
|
253
|
+
contents = contents.gsub(PLACEHOLDER_OBJECT, object)
|
254
|
+
contents = contents.gsub(PLACEHOLDER_OBJECT_LOWERCASE, object_lower)
|
255
|
+
|
256
|
+
write_file_java("#{get_java_path(@site, schema, SERVICE, PACKAGE)}/#{object}Validator.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
private
|
267
|
+
|
268
|
+
def build_switch
|
269
|
+
output = []
|
270
|
+
@validate_switch.each do |key, value|
|
271
|
+
output << " case #{PLACEHOLDER_OBJECT}MetaData.FIELD_#{key}:"
|
272
|
+
value.each { |line| output << line }
|
273
|
+
output << ' break;'
|
274
|
+
end
|
275
|
+
output
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlJavaWorkerWriter < Blufin::YmlWriterBase
|
4
|
+
|
5
|
+
SERVICE = Blufin::SiteServices::WORKER
|
6
|
+
PACKAGE = 'messages'
|
7
|
+
|
8
|
+
PLACEHOLDER_IMP = '{{--PLACEHOLDER-IMP--}}'
|
9
|
+
PLACEHOLDER_PUT = '{{--PLACEHOLDER-ONE--}}'
|
10
|
+
PLACEHOLDER_SITE_NAME = '{{--SITE-NAME--}}'
|
11
|
+
PLACEHOLDER_SITE_DOMAIN = '{{--SITE-DOMAIN--}}'
|
12
|
+
|
13
|
+
MESSAGE_HANDLER = 'MessageHandler'
|
14
|
+
MESSAGE_HANDLER_MAPPER = 'MessageHandlerMapper'
|
15
|
+
|
16
|
+
# Initialize the class.
|
17
|
+
# @return void
|
18
|
+
def initialize(site)
|
19
|
+
|
20
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
21
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
22
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
23
|
+
@site_domain_gsub = @site_domain.strip == '' ? '' : "#{@site_domain}."
|
24
|
+
@site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
|
25
|
+
|
26
|
+
# Wipe out parent file.
|
27
|
+
Blufin::Files::delete_file("#{get_java_path(@site, nil, SERVICE, PLACEHOLDER_PUT)}/#{MESSAGE_HANDLER_MAPPER}.java")
|
28
|
+
|
29
|
+
@template_parent = <<TEMPLATE
|
30
|
+
package #{PLACEHOLDER_PACKAGE};
|
31
|
+
|
32
|
+
import org.blufin.worker.queue.MessageHandlerInterface;
|
33
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.lib.enums.system.MessageType;
|
34
|
+
#{PLACEHOLDER_IMP}
|
35
|
+
|
36
|
+
import java.util.HashMap;
|
37
|
+
import java.util.Map;
|
38
|
+
|
39
|
+
public class #{MESSAGE_HANDLER_MAPPER} {
|
40
|
+
|
41
|
+
public static Map<String, MessageHandlerInterface> getMap() {
|
42
|
+
|
43
|
+
Map<String, MessageHandlerInterface> map = new HashMap<>();
|
44
|
+
|
45
|
+
#{PLACEHOLDER_PUT}
|
46
|
+
|
47
|
+
return map;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
TEMPLATE
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
# Write the file(s).
|
55
|
+
# @return void
|
56
|
+
def write
|
57
|
+
|
58
|
+
imp_statements = ''
|
59
|
+
put_statements = ''
|
60
|
+
|
61
|
+
message_types = Blufin::YmlConfigValidator::get_message_types.keys
|
62
|
+
message_types.each_with_index do |message_type, idx|
|
63
|
+
new_line_or_not = (idx == (message_types.length - 1)) ? '' : "\n"
|
64
|
+
imp_statements += "import #{@site_domain_gsub}#{@site_name.gsub('-', '.')}.worker.messages.#{Blufin::Strings::snake_case_to_camel_case_lower(message_type)}.#{Blufin::Strings::snake_case_to_camel_case(message_type)}#{MESSAGE_HANDLER};#{new_line_or_not}"
|
65
|
+
put_statements += " map.put(MessageType.#{message_type.upcase.gsub('-', '_')}.toString(), new #{Blufin::Strings::snake_case_to_camel_case(message_type)}#{MESSAGE_HANDLER}());#{new_line_or_not}"
|
66
|
+
end
|
67
|
+
|
68
|
+
contents = @template_parent
|
69
|
+
contents = contents.gsub(PLACEHOLDER_PACKAGE, get_package(@site, nil, PACKAGE, SERVICE))
|
70
|
+
contents = contents.gsub(PLACEHOLDER_IMP, imp_statements)
|
71
|
+
contents = contents.gsub(PLACEHOLDER_PUT, put_statements)
|
72
|
+
contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
|
73
|
+
contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
|
74
|
+
|
75
|
+
write_file_java("#{get_java_path(@site, nil, SERVICE, PACKAGE)}/#{MESSAGE_HANDLER_MAPPER}.java", Blufin::YmlCommon::convert_string_to_line_array(contents))
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,307 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlSqlStructureWriter < Blufin::YmlWriterBase
|
4
|
+
|
5
|
+
def initialize(site, schema_data)
|
6
|
+
|
7
|
+
@schema_data = schema_data
|
8
|
+
|
9
|
+
raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
|
10
|
+
|
11
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
12
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
13
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
14
|
+
@site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
|
15
|
+
|
16
|
+
@yml_enum_scanner = Blufin::ScannerJavaEnums.new(@site)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def write
|
21
|
+
|
22
|
+
# Remove ALL previous structure files.
|
23
|
+
Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
|
24
|
+
sfs = get_structure_files(schema)
|
25
|
+
next if sfs.nil? # Skip if user doesn't have the PATH_TO_RUBY config value.
|
26
|
+
structure_file = sfs[0]
|
27
|
+
foreign_key_file = sfs[1]
|
28
|
+
Blufin::Files::delete_file(structure_file)
|
29
|
+
Blufin::Files::delete_file(foreign_key_file)
|
30
|
+
end
|
31
|
+
|
32
|
+
@schema_data.each do |schema, schema_data|
|
33
|
+
|
34
|
+
# This filters out the "mock" schema used for testing.
|
35
|
+
next if schema == Blufin::YmlSchemaValidator::MOCK
|
36
|
+
|
37
|
+
fk_count = 0
|
38
|
+
idx_count = 0
|
39
|
+
|
40
|
+
@structure = []
|
41
|
+
@alter_table_lines = []
|
42
|
+
@fks = []
|
43
|
+
@link_tables = []
|
44
|
+
|
45
|
+
schema_data.each_with_index do |(table, table_data), idx|
|
46
|
+
|
47
|
+
if table_data.length > 0
|
48
|
+
|
49
|
+
primary_key = nil
|
50
|
+
indexes = []
|
51
|
+
indexes_unique = []
|
52
|
+
indexes_fulltext = []
|
53
|
+
foreign_keys = []
|
54
|
+
|
55
|
+
@structure << "-- Create #{table} table"
|
56
|
+
@structure << "CREATE TABLE `#{table}` ("
|
57
|
+
|
58
|
+
table_data.each do |column_name, column_data|
|
59
|
+
|
60
|
+
# Skip Placeholders
|
61
|
+
next if column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/ || column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/
|
62
|
+
|
63
|
+
@type = column_data[Blufin::YmlSchemaValidator::TYPE]
|
64
|
+
@fkey = !column_data[Blufin::YmlSchemaValidator::FKEY].nil?
|
65
|
+
|
66
|
+
# Skip Transient Objects.
|
67
|
+
next if [Blufin::ScannerJavaEmbeddedObjects::OBJECT].include?(@type)
|
68
|
+
|
69
|
+
# Create FKEY LINK tables
|
70
|
+
if column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
|
71
|
+
@link_tables << [
|
72
|
+
"#{schema}.#{table}",
|
73
|
+
column_name.dup.gsub("[#{Blufin::YmlSchemaValidator::LINK}]", '')
|
74
|
+
]
|
75
|
+
next
|
76
|
+
end
|
77
|
+
|
78
|
+
# Get the flags and check for indexes.
|
79
|
+
if column_data[Blufin::YmlSchemaValidator::FLAG].nil?
|
80
|
+
@flags = nil
|
81
|
+
indexes << " INDEX `#{schema}_#{table}_#{column_name}_idx` (`#{column_name}`)," if @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
82
|
+
else
|
83
|
+
@flags = Blufin::YmlCommon::extract_flags(column_data[Blufin::YmlSchemaValidator::FLAG])[0]
|
84
|
+
# See if this is a PRIMARY KEY
|
85
|
+
primary_key = column_name if @flags.primary_key
|
86
|
+
# See if there are any INDEXES
|
87
|
+
if @flags.index
|
88
|
+
if [Blufin::YmlSchemaValidator::TYPE_TEXT, Blufin::YmlSchemaValidator::TYPE_TEXT_LONG].include?(@type)
|
89
|
+
indexes_fulltext << " FULLTEXT `#{schema}_#{table}_#{column_name}_idx_fulltext` (`#{column_name}`),"
|
90
|
+
else
|
91
|
+
indexes << " INDEX `#{schema}_#{table}_#{column_name}_idx` (`#{column_name}`)," if @flags.unique.nil?
|
92
|
+
indexes_unique << " UNIQUE INDEX `#{schema}_#{table}_#{column_name}_uniq_idx` (`#{column_name}`)," if @flags.unique
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Check for FKs
|
98
|
+
unless column_data[Blufin::YmlSchemaValidator::FKEY].nil?
|
99
|
+
fk_count = fk_count + 1
|
100
|
+
fk_ref = column_data[Blufin::YmlSchemaValidator::FKEY].split('.') # The target in form -> app.ebay_user.id
|
101
|
+
foreign_key_lines = []
|
102
|
+
foreign_key_lines << "ADD CONSTRAINT `fk_#{fk_count}`"
|
103
|
+
foreign_key_lines << " FOREIGN KEY (`#{column_name}`)"
|
104
|
+
foreign_key_lines << " REFERENCES `#{fk_ref[1]}` (`#{fk_ref[2]}`)"
|
105
|
+
foreign_key_lines << ' ON DELETE RESTRICT'
|
106
|
+
foreign_key_lines << ' ON UPDATE CASCADE,'
|
107
|
+
foreign_keys << foreign_key_lines
|
108
|
+
end
|
109
|
+
|
110
|
+
column_definition = " `#{column_name}`"
|
111
|
+
|
112
|
+
determine_type(column_definition, column_data)
|
113
|
+
determine_not_null(column_definition, column_data)
|
114
|
+
determine_auto_increment(column_definition)
|
115
|
+
determine_comment(column_data[Blufin::YmlSchemaValidator::DESCRIPTION], column_definition)
|
116
|
+
|
117
|
+
@structure << "#{column_definition},"
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
# Add primary key (if any) ..
|
122
|
+
@structure << " PRIMARY KEY (`#{primary_key}`)," if primary_key != nil
|
123
|
+
|
124
|
+
# Add indexes (if any) ..
|
125
|
+
indexes_fulltext.each { |index_fulltext| @structure << index_fulltext } if indexes_fulltext.any?
|
126
|
+
indexes_unique.each { |index_unique| @structure << index_unique } if indexes_unique.any?
|
127
|
+
indexes.each { |index| @structure << index } if indexes.any?
|
128
|
+
|
129
|
+
# Add FKs (if any) ..
|
130
|
+
if foreign_keys.any?
|
131
|
+
@alter_table_lines << "-- Add #{table} FKs"
|
132
|
+
@alter_table_lines << "ALTER TABLE `#{table}`"
|
133
|
+
foreign_keys.each do |foreign_key_lines|
|
134
|
+
foreign_key_lines.each do |foreign_key_line|
|
135
|
+
@alter_table_lines << foreign_key_line
|
136
|
+
end
|
137
|
+
end
|
138
|
+
@alter_table_lines[@alter_table_lines.length - 1] = @alter_table_lines[@alter_table_lines.length - 1][0...-1]
|
139
|
+
@alter_table_lines[@alter_table_lines.length - 1] << ";\n"
|
140
|
+
end
|
141
|
+
|
142
|
+
@structure[@structure.length - 1] = @structure[@structure.length - 1][0...-1]
|
143
|
+
@structure << ") ENGINE = InnoDB;#{idx == (schema_data.length - 1) ? '' : "\n"}"
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
# Add LINK tables (if any) ..
|
150
|
+
if @link_tables.any?
|
151
|
+
@link_tables.each_with_index do |link_data, idx|
|
152
|
+
source_table = link_data[0].split('.')
|
153
|
+
target_table = link_data[1].split('.')
|
154
|
+
link_table_name = Blufin::YmlCommon::get_link_table_name(source_table[1], link_data[1])
|
155
|
+
|
156
|
+
# Create structure.
|
157
|
+
@structure << "-- Add table to link '#{source_table[1]}' with '#{target_table[1]}'"
|
158
|
+
@structure << "CREATE TABLE `#{link_table_name}` ("
|
159
|
+
@structure << " `#{source_table[1]}_id` INT NOT NULL,"
|
160
|
+
@structure << " `#{target_table[1]}_id` INT NOT NULL"
|
161
|
+
@structure << ") ENGINE = InnoDB;#{idx == (@link_tables.length - 1) ? '' : "\n"}"
|
162
|
+
|
163
|
+
# Create FKs and indexes.
|
164
|
+
@fks << "ALTER TABLE `#{link_table_name}`"
|
165
|
+
idx_count = idx_count + 1
|
166
|
+
@fks << " ADD INDEX `idx_#{idx_count}` (`#{source_table[1]}_id` DESC),"
|
167
|
+
idx_count = idx_count + 1
|
168
|
+
@fks << " ADD INDEX `idx_#{idx_count}` (`#{target_table[1]}_id` DESC),"
|
169
|
+
@fks << " ADD UNIQUE INDEX `#{source_table[1]}_to_#{target_table[1]}_uniq_idx` (`#{source_table[1]}_id` DESC, `#{target_table[1]}_id` DESC),"
|
170
|
+
fk_count = fk_count + 1
|
171
|
+
@fks << " ADD CONSTRAINT `fk_#{fk_count}`"
|
172
|
+
@fks << " FOREIGN KEY (`#{source_table[1]}_id`)"
|
173
|
+
@fks << " REFERENCES `#{source_table[1]}` (`id`)"
|
174
|
+
@fks << ' ON DELETE RESTRICT'
|
175
|
+
@fks << ' ON UPDATE RESTRICT,'
|
176
|
+
fk_count = fk_count + 1
|
177
|
+
@fks << " ADD CONSTRAINT `fk_#{fk_count}`"
|
178
|
+
@fks << " FOREIGN KEY (`#{target_table[1]}_id`)"
|
179
|
+
@fks << " REFERENCES `#{target_table[1]}` (`id`)"
|
180
|
+
@fks << ' ON DELETE RESTRICT'
|
181
|
+
@fks << ' ON UPDATE RESTRICT;'
|
182
|
+
@fks << '' unless idx == @link_tables.length - 1
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
sfs = get_structure_files(schema)
|
187
|
+
next if sfs.nil? # Skip if user doesn't have the PATH_TO_RUBY config value.
|
188
|
+
structure_file = sfs[0]
|
189
|
+
foreign_key_file = sfs[1]
|
190
|
+
|
191
|
+
Blufin::Files.write_file(structure_file, @structure).gsub(@site_location, '') if @structure.any?
|
192
|
+
Blufin::Files.write_file(foreign_key_file, @alter_table_lines + @fks).gsub(@site_location, '') if @alter_table_lines.any? || @fks.any?
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
private
|
199
|
+
|
200
|
+
# @return void
|
201
|
+
def determine_type(column_definition, column_data)
|
202
|
+
|
203
|
+
if @type == Blufin::YmlSchemaValidator::TYPE_DATE
|
204
|
+
# Must come before DATETIME_TYPES.include?
|
205
|
+
column_definition << ' DATE'
|
206
|
+
elsif Blufin::YmlSchemaValidator::DATETIME_TYPES.include?(@type)
|
207
|
+
column_definition << ' DATETIME(3)'
|
208
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_TINY
|
209
|
+
column_definition << ' TINYINT'
|
210
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
|
211
|
+
column_definition << ' SMALLINT'
|
212
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_BIG
|
213
|
+
column_definition << ' BIGINT'
|
214
|
+
elsif Blufin::YmlSchemaValidator::INT_TYPES.include?(@type)
|
215
|
+
column_definition << ' INT'
|
216
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
217
|
+
column_definition << ' TINYINT(1)'
|
218
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT
|
219
|
+
column_definition << ' TEXT'
|
220
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT_LONG
|
221
|
+
column_definition << ' LONGTEXT'
|
222
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL || @type =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
|
223
|
+
if column_data[Blufin::YmlSchemaValidator::ENCRYPTED].nil?
|
224
|
+
column_definition << " #{@type}"
|
225
|
+
else
|
226
|
+
# Encrypted VARCHAR(30) would become VARCHAR(60).
|
227
|
+
varchar_amount = Blufin::Strings::extract_using_regex(@type, /\(\d+\)\z/, %w{( )})
|
228
|
+
column_definition << " #{Blufin::YmlSchemaValidator::TYPE_VARCHAR}(#{varchar_amount.to_i * 2})"
|
229
|
+
end
|
230
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
231
|
+
enum_values = Blufin::YmlCommon::enum_value_extractor(@type, @site)
|
232
|
+
column_definition << " VARCHAR(#{enum_values.max_by(&:length).length})"
|
233
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM
|
234
|
+
enum_values = @yml_enum_scanner.get_enum_custom_values_for(Blufin::YmlCommon::enum_name_extractor(@type))
|
235
|
+
column_definition << " VARCHAR(#{enum_values.max_by(&:length).length})"
|
236
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
237
|
+
enum_values = @yml_enum_scanner.get_enum_system_values_for(Blufin::YmlCommon::enum_name_extractor(@type))
|
238
|
+
column_definition << " VARCHAR(#{enum_values.max_by(&:length).length})"
|
239
|
+
else
|
240
|
+
raise RuntimeError, "Unrecognized type in #{__FILE__}: #{@type}"
|
241
|
+
end
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
# @return void
|
246
|
+
def determine_not_null(column_definition, column_data)
|
247
|
+
|
248
|
+
((@flags != nil && @flags.nullable) || column_data.has_key?(Blufin::YmlSchemaValidator::REQUIRED_IF)) ?
|
249
|
+
column_definition << ' NULL' :
|
250
|
+
column_definition << ' NOT NULL'
|
251
|
+
end
|
252
|
+
|
253
|
+
# @return void
|
254
|
+
def determine_auto_increment(column_definition)
|
255
|
+
column_definition << ' AUTO_INCREMENT' if @type == Blufin::YmlSchemaValidator::TYPE_INT_AUTO
|
256
|
+
end
|
257
|
+
|
258
|
+
# @return void
|
259
|
+
def determine_comment(description, column_definition)
|
260
|
+
|
261
|
+
if description != nil
|
262
|
+
desc = description
|
263
|
+
else
|
264
|
+
desc = ''
|
265
|
+
end
|
266
|
+
|
267
|
+
desc = Blufin::YmlCommon::description_without_formatting(desc)
|
268
|
+
|
269
|
+
if @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
270
|
+
desc << " \xe2\x80\x94 " unless desc == '' || desc.nil?
|
271
|
+
desc << '['
|
272
|
+
Blufin::YmlCommon::enum_value_extractor(@type, @site).each do |enum_value|
|
273
|
+
desc << "#{enum_value}|"
|
274
|
+
end
|
275
|
+
desc = desc[0...-1]
|
276
|
+
desc << ']'
|
277
|
+
end
|
278
|
+
|
279
|
+
column_definition << " COMMENT '#{desc.gsub("'", %q(\\\'))}'" if desc != nil && desc.to_s != ''
|
280
|
+
|
281
|
+
end
|
282
|
+
|
283
|
+
# @return Array
|
284
|
+
def get_structure_files(schema)
|
285
|
+
|
286
|
+
if schema == Blufin::YmlSchemaValidator::CONFIG
|
287
|
+
path_to_blufin_ruby = Blufin::Config::get_path('Paths', 'BlufinRuby')
|
288
|
+
return nil if path_to_blufin_ruby.nil?
|
289
|
+
structure_file = "#{path_to_blufin_ruby}/#{App::Opt::BLUFIN}#{App::Opt::OPT_PATH_SQL}/structure/#{App::MySQL::CONFIG_FILENAME_STRUCTURE}"
|
290
|
+
foreign_key_file = "#{path_to_blufin_ruby}/#{App::Opt::BLUFIN}#{App::Opt::OPT_PATH_SQL}/structure/#{App::MySQL::CONFIG_FILENAME_STRUCTURE_FKS}"
|
291
|
+
elsif schema == Blufin::YmlSchemaValidator::MOCK
|
292
|
+
path_to_blufin_ruby = Blufin::Config::get_path('Paths', 'BlufinRuby')
|
293
|
+
return nil if path_to_blufin_ruby.nil?
|
294
|
+
structure_file = "#{path_to_blufin_ruby}/#{App::Opt::BLUFIN}#{App::Opt::OPT_PATH_SQL}/structure/#{App::MySQL::MOCK_FILENAME_STRUCTURE}"
|
295
|
+
foreign_key_file = "#{path_to_blufin_ruby}/#{App::Opt::BLUFIN}#{App::Opt::OPT_PATH_SQL}/structure/#{App::MySQL::MOCK_FILENAME_STRUCTURE_FKS}"
|
296
|
+
else
|
297
|
+
structure_file = "#{get_base_path(@site)}/#{Blufin::Site::PATH_TO_SQL_STRUCTURE}/#{Blufin::SiteResolver::get_site_name(@site)}-#{schema}.sql"
|
298
|
+
foreign_key_file = "#{get_base_path(@site)}/#{Blufin::Site::PATH_TO_SQL_STRUCTURE}/#{Blufin::SiteResolver::get_site_name(@site)}-fks-#{schema}.sql"
|
299
|
+
end
|
300
|
+
|
301
|
+
[structure_file, foreign_key_file]
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
end
|