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,59 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlJavaCssDependencyWriter < 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,364 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlJavaDaoWriter < Blufin::YmlWriterBase
|
4
|
+
|
5
|
+
SERVICE = Blufin::SiteServices::API
|
6
|
+
PACKAGE = "#{Blufin::SiteServices::PACKAGE_AUTO_GENERATED}.dao"
|
7
|
+
|
8
|
+
PLACEHOLDER_SITE_NAME = '{{--SITE-NAME--}}'
|
9
|
+
PLACEHOLDER_SITE_DOMAIN = '{{--SITE-DOMAIN--}}'
|
10
|
+
PLACEHOLDER_OBJECT = '{{--OBJECT--}}'
|
11
|
+
PLACEHOLDER_OBJECT_LOWER = '{{--OBJECT-LOWER--}}'
|
12
|
+
PLACEHOLDER_TABLE = '{{--TABLE--}}'
|
13
|
+
PLACEHOLDER_PARENT_TABLE = '{{--PARENT-TABLE--}}'
|
14
|
+
PLACEHOLDER_PREPARE_POST = '{{--PREPARE-POST--}}'
|
15
|
+
PLACEHOLDER_PREPARE_PUT = '{{--PREPARE-PUT--}}'
|
16
|
+
PLACEHOLDER_GET_DEPENDENTS = '{{--GET-DEPENDENTS--}}'
|
17
|
+
PLACEHOLDER_MAP_ONE_BODY = '{{--MAP-ONE-BODY--}}'
|
18
|
+
PLACEHOLDER_MAP_TWO_BODY = '{{--MAP-TWO-BODY--}}'
|
19
|
+
PLACEHOLDER_POST_FIELDS = '{{--POST-FIELDS--}}'
|
20
|
+
PLACEHOLDER_POST_VALUES = '{{--POST-VALUES--}}'
|
21
|
+
PLACEHOLDER_PUT_FIELDS = '{{--PUT-FIELDS--}}'
|
22
|
+
|
23
|
+
# @return void
|
24
|
+
def initialize(site, schema_data, schema_resources, schema_fks)
|
25
|
+
|
26
|
+
@schema_data = schema_data
|
27
|
+
@schema_resources = schema_resources
|
28
|
+
@schema_fks = schema_fks
|
29
|
+
|
30
|
+
raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
|
31
|
+
raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash)
|
32
|
+
|
33
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
34
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
35
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
36
|
+
@site_domain_gsub = @site_domain.strip == '' ? '' : "#{@site_domain}."
|
37
|
+
@site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
|
38
|
+
|
39
|
+
# Wipe out all previous files.
|
40
|
+
Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
|
41
|
+
path_to_wipe_out = "#{get_java_path(@site, schema, SERVICE, PACKAGE)}"
|
42
|
+
if Blufin::Files::path_exists(path_to_wipe_out)
|
43
|
+
if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
|
44
|
+
Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@template = <<TEMPLATE
|
50
|
+
package #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.api.#{PACKAGE};
|
51
|
+
|
52
|
+
import org.blufin.api.base.AbstractDao;
|
53
|
+
import org.blufin.base.utils.UtilsLogger;
|
54
|
+
import org.blufin.base.exceptions.BlufinClientException;
|
55
|
+
import org.blufin.base.exceptions.BlufinAlertDeveloperException;
|
56
|
+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
57
|
+
import org.blufin.base.helper.IdSet;
|
58
|
+
import org.blufin.sdk.rest.GetRequest;
|
59
|
+
import #{PLACEHOLDER_SITE_DOMAIN}#{PLACEHOLDER_SITE_NAME}.sdk.dto.#{PLACEHOLDER_OBJECT};
|
60
|
+
import lombok.Getter;
|
61
|
+
import org.blufin.sdk.enums.PayloadType;
|
62
|
+
import org.blufin.base.enums.DataType;
|
63
|
+
import org.blufin.base.helper.Pair;
|
64
|
+
import org.blufin.base.helper.Triplet;
|
65
|
+
import java.util.Map;
|
66
|
+
import java.util.HashMap;
|
67
|
+
import java.util.List;
|
68
|
+
import java.util.ArrayList;
|
69
|
+
import java.util.Collections;
|
70
|
+
import java.sql.ResultSet;
|
71
|
+
import java.sql.Connection;
|
72
|
+
import java.sql.Statement;
|
73
|
+
import java.sql.PreparedStatement;
|
74
|
+
import org.springframework.stereotype.Service;
|
75
|
+
import java.sql.SQLException;#{PLACEHOLDER_IMPORT}
|
76
|
+
|
77
|
+
@Service
|
78
|
+
public class #{PLACEHOLDER_OBJECT}Dao extends AbstractDao<#{PLACEHOLDER_OBJECT}> {
|
79
|
+
|
80
|
+
@Getter
|
81
|
+
private static final #{PLACEHOLDER_OBJECT}Dao instance = new #{PLACEHOLDER_OBJECT}Dao();
|
82
|
+
|
83
|
+
private #{PLACEHOLDER_OBJECT}Dao() {
|
84
|
+
|
85
|
+
super("#{PLACEHOLDER_TABLE}", #{PLACEHOLDER_PARENT_TABLE});
|
86
|
+
}
|
87
|
+
|
88
|
+
@Override
|
89
|
+
public List<#{PLACEHOLDER_OBJECT}> map(ResultSet rs) throws SQLException {
|
90
|
+
|
91
|
+
List<#{PLACEHOLDER_OBJECT}> #{PLACEHOLDER_OBJECT_LOWER}List = new ArrayList<>();
|
92
|
+
|
93
|
+
while(rs.next()) {
|
94
|
+
|
95
|
+
#{PLACEHOLDER_OBJECT} #{PLACEHOLDER_OBJECT_LOWER} = new #{PLACEHOLDER_OBJECT}();
|
96
|
+
|
97
|
+
#{PLACEHOLDER_MAP_ONE_BODY}
|
98
|
+
|
99
|
+
#{PLACEHOLDER_OBJECT_LOWER}List.add(#{PLACEHOLDER_OBJECT_LOWER});
|
100
|
+
}
|
101
|
+
|
102
|
+
return #{PLACEHOLDER_OBJECT_LOWER}List;
|
103
|
+
}
|
104
|
+
|
105
|
+
@Override
|
106
|
+
public List<Map<String, String>> map(ResultSet rs, List<String> fields) {
|
107
|
+
|
108
|
+
#{PLACEHOLDER_MAP_TWO_BODY}
|
109
|
+
}
|
110
|
+
|
111
|
+
@Override
|
112
|
+
@SuppressFBWarnings
|
113
|
+
protected PreparedStatement preparePostStatement(Connection connection, #{PLACEHOLDER_OBJECT} #{PLACEHOLDER_OBJECT_LOWER}) throws SQLException {
|
114
|
+
|
115
|
+
PreparedStatement statement = connection.prepareStatement("INSERT INTO #{PLACEHOLDER_TABLE} (#{PLACEHOLDER_POST_FIELDS}) VALUES (#{PLACEHOLDER_POST_VALUES})", Statement.RETURN_GENERATED_KEYS);
|
116
|
+
|
117
|
+
#{PLACEHOLDER_PREPARE_POST}
|
118
|
+
return statement;
|
119
|
+
}
|
120
|
+
|
121
|
+
@Override
|
122
|
+
@SuppressFBWarnings
|
123
|
+
protected PreparedStatement preparePutStatement(Connection connection, #{PLACEHOLDER_OBJECT} #{PLACEHOLDER_OBJECT_LOWER}) throws SQLException {
|
124
|
+
|
125
|
+
PreparedStatement statement = connection.prepareStatement("UPDATE #{PLACEHOLDER_TABLE} SET #{PLACEHOLDER_PUT_FIELDS} WHERE `id` = ?", Statement.RETURN_GENERATED_KEYS);
|
126
|
+
|
127
|
+
#{PLACEHOLDER_PREPARE_PUT}
|
128
|
+
return statement;
|
129
|
+
}
|
130
|
+
|
131
|
+
@Override
|
132
|
+
protected List<Triplet<AbstractDao, String, DataType>> getDependents() {
|
133
|
+
|
134
|
+
#{PLACEHOLDER_GET_DEPENDENTS}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
TEMPLATE
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
# @return void
|
142
|
+
def write
|
143
|
+
|
144
|
+
@schema_data.each do |schema, schema_data|
|
145
|
+
|
146
|
+
schema_data.each do |table, table_data|
|
147
|
+
|
148
|
+
if table_data.length > 0
|
149
|
+
|
150
|
+
contents = @template
|
151
|
+
|
152
|
+
table_camel_case = Blufin::Strings::snake_case_to_camel_case(table)
|
153
|
+
table_camel_case_lower = Blufin::Strings::snake_case_to_camel_case_lower(table)
|
154
|
+
|
155
|
+
dto_method_body = []
|
156
|
+
import_statements = []
|
157
|
+
field_names_post = []
|
158
|
+
field_names_put = []
|
159
|
+
prepare_post = []
|
160
|
+
prepare_put = []
|
161
|
+
get_dependents = []
|
162
|
+
idx_post = 0
|
163
|
+
idx_put = 0
|
164
|
+
|
165
|
+
table_data.each do |column_name, column_data|
|
166
|
+
|
167
|
+
# Skip Placeholders
|
168
|
+
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}\]/
|
169
|
+
|
170
|
+
@type = column_data[Blufin::YmlSchemaValidator::TYPE]
|
171
|
+
@fkey = column_data.has_key?(Blufin::YmlSchemaValidator::FKEY)
|
172
|
+
@is_child = column_data.has_key?(Blufin::YmlSchemaValidator::CHILD_OF) && column_data.has_key?(Blufin::YmlSchemaValidator::CHILD_TYPE)
|
173
|
+
|
174
|
+
# Skip Transient Objects.
|
175
|
+
next if [Blufin::ScannerJavaEmbeddedObjects::OBJECT].include?(@type)
|
176
|
+
|
177
|
+
# Handle ID column differently.
|
178
|
+
if column_name == Blufin::YmlSchemaValidator::ID
|
179
|
+
dto_method_body << " #{table_camel_case_lower}.setId(rs.getInt(\"id\"));"
|
180
|
+
next
|
181
|
+
end
|
182
|
+
|
183
|
+
field_camel_case = Blufin::Strings.snake_case_to_camel_case(column_name.dup)
|
184
|
+
|
185
|
+
if [Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT].include?(@type)
|
186
|
+
idx_post += 1
|
187
|
+
field_names_post << column_name.dup
|
188
|
+
else
|
189
|
+
idx_post += 1
|
190
|
+
idx_put += 1 unless @is_child
|
191
|
+
field_names_post << column_name.dup
|
192
|
+
field_names_put << column_name.dup unless @is_child
|
193
|
+
end
|
194
|
+
|
195
|
+
if @type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
196
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getBoolean(\"#{column_name}\"));"
|
197
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.BOOLEAN, #{table_camel_case_lower}.is#{field_camel_case}());"
|
198
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.BOOLEAN, #{table_camel_case_lower}.is#{field_camel_case}());"
|
199
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_DATE
|
200
|
+
import_statements << 'import org.blufin.base.utils.UtilsDate;'
|
201
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(getLocalDate(rs.getDate(\"#{column_name}\")));"
|
202
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.DATE, #{table_camel_case_lower}.get#{field_camel_case}());"
|
203
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.DATE, #{table_camel_case_lower}.get#{field_camel_case}());"
|
204
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_DATETIME
|
205
|
+
import_statements << 'import org.blufin.core.auth.client.ClientData;'
|
206
|
+
import_statements << 'import org.blufin.base.utils.UtilsDate;'
|
207
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(getZonedDateTime(rs.getTimestamp(\"#{column_name}\"), ClientData.getTimeZone().getZoneId()));"
|
208
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.DATETIME, #{table_camel_case_lower}.get#{field_camel_case}());"
|
209
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.DATETIME, #{table_camel_case_lower}.get#{field_camel_case}());"
|
210
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT
|
211
|
+
import_statements << 'import java.time.ZonedDateTime;'
|
212
|
+
import_statements << 'import org.blufin.base.utils.UtilsDate;'
|
213
|
+
import_statements << 'import org.blufin.core.auth.client.ClientData;'
|
214
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(getZonedDateTime(rs.getTimestamp(\"#{column_name}\"), ClientData.getTimeZone().getZoneId()));"
|
215
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.DATETIME_INSERT, null);"
|
216
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_DATETIME_UPDATE
|
217
|
+
import_statements << 'import java.time.ZonedDateTime;'
|
218
|
+
import_statements << 'import org.blufin.base.utils.UtilsDate;'
|
219
|
+
import_statements << 'import org.blufin.core.auth.client.ClientData;'
|
220
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(getZonedDateTime(rs.getTimestamp(\"#{column_name}\"), ClientData.getTimeZone().getZoneId()));"
|
221
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.DATETIME_UPDATE, null);"
|
222
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.DATETIME_UPDATE, null);"
|
223
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL
|
224
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getBigDecimal(\"#{column_name}\"));"
|
225
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.DECIMAL, #{table_camel_case_lower}.get#{field_camel_case}());"
|
226
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.DECIMAL, #{table_camel_case_lower}.get#{field_camel_case}());"
|
227
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_TINY
|
228
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getByte(\"#{column_name}\"));"
|
229
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.INT_TINY, #{table_camel_case_lower}.get#{field_camel_case}());"
|
230
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.INT_TINY, #{table_camel_case_lower}.get#{field_camel_case}());"
|
231
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
|
232
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getShort(\"#{column_name}\"));"
|
233
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.INT_SMALL, #{table_camel_case_lower}.get#{field_camel_case}());"
|
234
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.INT_SMALL, #{table_camel_case_lower}.get#{field_camel_case}());"
|
235
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_INT_BIG
|
236
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getLong(\"#{column_name}\"));"
|
237
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.INT_BIG, #{table_camel_case_lower}.get#{field_camel_case}());"
|
238
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.INT_BIG, #{table_camel_case_lower}.get#{field_camel_case}());"
|
239
|
+
elsif Blufin::YmlSchemaValidator::INT_TYPES.include?(@type)
|
240
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getInt(\"#{column_name}\"));"
|
241
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.INT, #{table_camel_case_lower}.get#{field_camel_case}());"
|
242
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.INT, #{table_camel_case_lower}.get#{field_camel_case}());" unless @is_child
|
243
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT
|
244
|
+
if column_data[Blufin::YmlSchemaValidator::ENCRYPTED].nil?
|
245
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getString(\"#{column_name}\"));"
|
246
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.TEXT, #{table_camel_case_lower}.get#{field_camel_case}());"
|
247
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.TEXT, #{table_camel_case_lower}.get#{field_camel_case}());"
|
248
|
+
else
|
249
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(Encryptor.decryptWithoutException(rs.getString(\"#{column_name}\")));"
|
250
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.TEXT, Encryptor.encryptWithoutException(#{table_camel_case_lower}.get#{field_camel_case}()));"
|
251
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.TEXT, Encryptor.encryptWithoutException(#{table_camel_case_lower}.get#{field_camel_case}()));"
|
252
|
+
import_statements << 'import org.blufin.core.security.Encryptor;'
|
253
|
+
end
|
254
|
+
elsif @type == Blufin::YmlSchemaValidator::TYPE_TEXT_LONG
|
255
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.TEXT_LONG, #{table_camel_case_lower}.get#{field_camel_case}());"
|
256
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.TEXT_LONG, #{table_camel_case_lower}.get#{field_camel_case}());"
|
257
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
258
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(#{table_camel_case}#{field_camel_case}.get(rs.getString(\"#{column_name}\")));"
|
259
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.ENUM, #{table_camel_case_lower}.get#{field_camel_case}().toString());"
|
260
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.ENUM, #{table_camel_case_lower}.get#{field_camel_case}().toString());"
|
261
|
+
import_statements << "import #{get_package(@site, schema, 'enums', Blufin::SiteServices::SDK)}.#{table_camel_case}#{field_camel_case};"
|
262
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM
|
263
|
+
enum_class_name = Blufin::YmlCommon::enum_name_extractor(@type)
|
264
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(#{enum_class_name}.valueOf(rs.getString(\"#{column_name}\")));"
|
265
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.ENUM_CUSTOM, #{table_camel_case_lower}.get#{field_camel_case}().toString());"
|
266
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.ENUM_CUSTOM, #{table_camel_case_lower}.get#{field_camel_case}().toString());"
|
267
|
+
import_statements << "import #{get_package(@site, schema, 'enums', Blufin::SiteServices::SDK)}.#{enum_class_name};"
|
268
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
269
|
+
enum_class_name = Blufin::YmlCommon::enum_name_extractor(@type)
|
270
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(#{enum_class_name}.valueOf(rs.getString(\"#{column_name}\")));"
|
271
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.ENUM_SYSTEM, #{table_camel_case_lower}.get#{field_camel_case}().toString());"
|
272
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.ENUM_SYSTEM, #{table_camel_case_lower}.get#{field_camel_case}().toString());"
|
273
|
+
import_statements << "import #{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS}.#{enum_class_name};"
|
274
|
+
elsif @type =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
|
275
|
+
dto_method_body << " #{table_camel_case_lower}.set#{field_camel_case}(rs.getString(\"#{column_name}\"));"
|
276
|
+
prepare_post << " setParameter(#{idx_post}, statement, DataType.VARCHAR, #{table_camel_case_lower}.get#{field_camel_case}());"
|
277
|
+
prepare_put << " setParameter(#{idx_put}, statement, DataType.VARCHAR, #{table_camel_case_lower}.get#{field_camel_case}());"
|
278
|
+
else
|
279
|
+
raise RuntimeError, "Unrecognized type in #{__FILE__}: #{@type}"
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
last_post_idx = 0
|
285
|
+
last_put_idx = 0
|
286
|
+
|
287
|
+
# Sanity check (POST). Makes sure there are no gaps in the indexes -- just to make me feel better :)
|
288
|
+
prepare_post.each do |post|
|
289
|
+
matches = post.match(/\([0-9]{1,3},/)
|
290
|
+
raise RuntimeError, 'Unable to extract index.' unless matches.length == 1
|
291
|
+
matched_idx = matches[0].gsub(/\(/, '').gsub(',', '')
|
292
|
+
raise RuntimeError, "\n#{schema}.#{table} POST index(es) not in sequence:\n#{prepare_post.to_yaml}" unless matched_idx.to_i == (last_post_idx + 1).to_i
|
293
|
+
last_post_idx += 1
|
294
|
+
end
|
295
|
+
|
296
|
+
# Sanity check (PUT). Same as above.
|
297
|
+
prepare_put.each do |put|
|
298
|
+
matches = put.match(/\([0-9]{1,3},/)
|
299
|
+
raise RuntimeError, 'Unable to extract index.' unless matches.length == 1
|
300
|
+
matched_idx = matches[0].gsub(/\(/, '').gsub(',', '')
|
301
|
+
raise RuntimeError, "\n#{schema}.#{table} PUT Index(es) not in sequence:\n#{prepare_put.to_yaml}" unless matched_idx.to_i == (last_put_idx + 1).to_i
|
302
|
+
last_put_idx += 1
|
303
|
+
end
|
304
|
+
|
305
|
+
# Must add the "WHERE `id` = ?" parameter for PUTs.
|
306
|
+
prepare_put << " setParameter(#{idx_put + 1}, statement, DataType.INT, #{table_camel_case_lower}.getId());"
|
307
|
+
|
308
|
+
parent_table = @schema_resources["#{schema}.#{table}"][:parent]
|
309
|
+
parent_table = parent_table.nil? ? 'null' : '"' + parent_table + '"'
|
310
|
+
|
311
|
+
# Add getDependents() stuff (if any).
|
312
|
+
schema_fks = @schema_fks["#{schema}.#{table}.#{Blufin::YmlSchemaValidator::ID}"]
|
313
|
+
if schema_fks && schema_fks.any?
|
314
|
+
get_dependents << ' List<Triplet<AbstractDao, String, DataType>> dependents = new ArrayList<>();'
|
315
|
+
get_dependents << ''
|
316
|
+
schema_fks.each do |schema_fk|
|
317
|
+
fk_split = schema_fk.split('.')
|
318
|
+
fk_table = fk_split[1]
|
319
|
+
fk_field = fk_split[2].split(':')[0]
|
320
|
+
fk_type = @schema_data[schema][fk_table][fk_field][Blufin::YmlSchemaValidator::CHILD_TYPE]
|
321
|
+
get_dependents << " dependents.add(Triplet.of(#{Blufin::Strings::snake_case_to_camel_case(fk_table)}Dao.getInstance(), \"#{fk_field}\", #{fk_type.nil? ? 'null' : fk_type}));"
|
322
|
+
end
|
323
|
+
get_dependents << ''
|
324
|
+
get_dependents << ' return dependents;'
|
325
|
+
else
|
326
|
+
get_dependents << ' return null;'
|
327
|
+
end
|
328
|
+
|
329
|
+
import_statements.sort!
|
330
|
+
import_statements.uniq!
|
331
|
+
|
332
|
+
field_names_post.map! { |n| "`#{n}`" }
|
333
|
+
field_names_put.map! { |n| "`#{n}`" }
|
334
|
+
|
335
|
+
contents = contents.gsub(PLACEHOLDER_SITE_NAME, @site_name.gsub('-', '.'))
|
336
|
+
contents = contents.gsub(PLACEHOLDER_SITE_DOMAIN, @site_domain_gsub)
|
337
|
+
contents = contents.gsub(PLACEHOLDER_SCHEMA, schema)
|
338
|
+
contents = contents.gsub(PLACEHOLDER_OBJECT, table_camel_case)
|
339
|
+
contents = contents.gsub(PLACEHOLDER_OBJECT_LOWER, table_camel_case_lower)
|
340
|
+
contents = contents.gsub(PLACEHOLDER_TABLE, table)
|
341
|
+
contents = contents.gsub(PLACEHOLDER_PARENT_TABLE, parent_table)
|
342
|
+
contents = contents.gsub(PLACEHOLDER_IMPORT, import_statements.any? ? "\n#{import_statements.join("\n")}" : '')
|
343
|
+
contents = contents.gsub(PLACEHOLDER_PREPARE_POST, (prepare_post + ["\n"]).join("\n"))
|
344
|
+
contents = contents.gsub(PLACEHOLDER_PREPARE_PUT, (prepare_put + ["\n"]).join("\n"))
|
345
|
+
contents = contents.gsub(PLACEHOLDER_GET_DEPENDENTS, (get_dependents).join("\n"))
|
346
|
+
contents = contents.gsub(PLACEHOLDER_MAP_ONE_BODY, dto_method_body.join("\n"))
|
347
|
+
contents = contents.gsub(PLACEHOLDER_POST_FIELDS, field_names_post.join(', ').to_s)
|
348
|
+
contents = contents.gsub(PLACEHOLDER_POST_VALUES, ('?, ' * field_names_post.length)[0...-2])
|
349
|
+
contents = contents.gsub(PLACEHOLDER_PUT_FIELDS, field_names_put.any? ? "#{field_names_put.join(' = ?, ')} = ?" : 'id = id')
|
350
|
+
contents = contents.gsub(PLACEHOLDER_MAP_TWO_BODY, ' return null;') # TODO - FINISH THIS
|
351
|
+
|
352
|
+
write_file_java("#{get_java_path(@site, schema, SERVICE, PACKAGE)}/#{table_camel_case}Dao.java", Blufin::YmlCommon::convert_string_to_line_array(contents), schema == Blufin::YmlSchemaValidator::MOCK)
|
353
|
+
|
354
|
+
end
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
361
|
+
|
362
|
+
end
|
363
|
+
|
364
|
+
end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class YmlJavaDtoWriter < Blufin::YmlWriterBase
|
4
|
+
|
5
|
+
SERVICE = Blufin::SiteServices::SDK_INTERNAL
|
6
|
+
PACKAGE = 'dto'
|
7
|
+
|
8
|
+
# @return void
|
9
|
+
def initialize(site, schema_data, schema_resources)
|
10
|
+
|
11
|
+
@schema_data = schema_data
|
12
|
+
@schema_resources = schema_resources
|
13
|
+
|
14
|
+
raise RuntimeError, 'Could not find valid @schema_data.' if @schema_data.nil? || !@schema_data.is_a?(Hash)
|
15
|
+
raise RuntimeError, 'Could not find valid @schema_resources.' if @schema_resources.nil? || !@schema_resources.is_a?(Hash)
|
16
|
+
|
17
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
18
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
19
|
+
@site_domain = Blufin::SiteResolver::get_site_domain(@site)
|
20
|
+
@site_location = "#{Blufin::SiteResolver::get_site_location(@site)}/"
|
21
|
+
|
22
|
+
# Wipe out all previous files.
|
23
|
+
Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE.each do |schema|
|
24
|
+
paths_to_wipe_out = %W(#{get_java_path(@site, schema, SERVICE, PACKAGE)})
|
25
|
+
paths_to_wipe_out.each do |path_to_wipe_out|
|
26
|
+
if Blufin::Files::path_exists(path_to_wipe_out)
|
27
|
+
if Blufin::Files::get_files_in_dir(path_to_wipe_out).any?
|
28
|
+
Blufin::Terminal::command('rm *', path_to_wipe_out, false, false)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return void
|
36
|
+
# noinspection RubyUnusedLocalVariable
|
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.is_a?(Hash) && table_data.length > 0
|
44
|
+
|
45
|
+
import_statements = []
|
46
|
+
instance_variables = []
|
47
|
+
special_getters = []
|
48
|
+
|
49
|
+
class_name = Blufin::Strings::snake_case_to_camel_case(table)
|
50
|
+
|
51
|
+
table_data.each do |column_name, column_data|
|
52
|
+
|
53
|
+
if column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/ || column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/
|
54
|
+
column_name_dup = column_name.dup.split('.')[1]
|
55
|
+
field_camel_case = Blufin::Strings.snake_case_to_camel_case(column_name_dup)
|
56
|
+
field_camel_case_lower = Blufin::Strings.snake_case_to_camel_case_lower(column_name_dup)
|
57
|
+
elsif column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
|
58
|
+
column_name_dup = column_name.dup.gsub("[#{Blufin::YmlSchemaValidator::LINK}]", '[]').split('.')[1]
|
59
|
+
field_camel_case = Blufin::Strings.snake_case_to_camel_case(column_name_dup)
|
60
|
+
field_camel_case_lower = Blufin::Strings.snake_case_to_camel_case_lower(column_name_dup)
|
61
|
+
else
|
62
|
+
field_camel_case = Blufin::Strings.snake_case_to_camel_case(column_name.dup)
|
63
|
+
field_camel_case_lower = Blufin::Strings.snake_case_to_camel_case_lower(column_name.dup)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Handle Placeholders
|
67
|
+
if column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/ || column_name =~ /\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
|
68
|
+
field_camel_case = field_camel_case.gsub('[]', '')
|
69
|
+
field_camel_case_lower = field_camel_case_lower.gsub('[]', '')
|
70
|
+
instance_variables << " private List<#{field_camel_case}> #{field_camel_case_lower}List = new ArrayList<>();#{write_column_description(column_data)}"
|
71
|
+
import_statements << 'import java.util.HashMap;'
|
72
|
+
import_statements << 'import java.util.Map;'
|
73
|
+
import_statements << 'import java.util.ArrayList;'
|
74
|
+
import_statements << 'import java.util.List;'
|
75
|
+
next
|
76
|
+
elsif column_name =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/
|
77
|
+
instance_variables << " private #{field_camel_case} #{field_camel_case_lower};#{write_column_description(column_data)}"
|
78
|
+
next
|
79
|
+
end
|
80
|
+
|
81
|
+
special_instance_variable = []
|
82
|
+
|
83
|
+
type = column_data[Blufin::YmlSchemaValidator::TYPE]
|
84
|
+
|
85
|
+
begin
|
86
|
+
nullable = column_data[Blufin::YmlSchemaValidator::FLAG].split(' ').include?(Blufin::YmlSchemaValidator::FLAG_NULLABLE)
|
87
|
+
rescue
|
88
|
+
nullable = false
|
89
|
+
end
|
90
|
+
|
91
|
+
if type == Blufin::YmlSchemaValidator::TYPE_BOOLEAN
|
92
|
+
import_statements << 'import lombok.AccessLevel;'
|
93
|
+
import_statements << 'import lombok.Getter;'
|
94
|
+
# special_instance_variable << '' unless instance_variables.last == ''
|
95
|
+
special_instance_variable << ' @Getter(AccessLevel.NONE)'
|
96
|
+
special_instance_variable << " private Boolean #{field_camel_case_lower};#{write_column_description(column_data)}"
|
97
|
+
# special_instance_variable << ''
|
98
|
+
special_getters << ''
|
99
|
+
special_getters << " public Boolean is#{field_camel_case}() {"
|
100
|
+
special_getters << ''
|
101
|
+
special_getters << " return #{field_camel_case_lower};"
|
102
|
+
special_getters << ' }'
|
103
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_DATETIME
|
104
|
+
type = 'ZonedDateTime'
|
105
|
+
import_statements << 'import java.time.ZonedDateTime;'
|
106
|
+
elsif [
|
107
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_INSERT,
|
108
|
+
Blufin::YmlSchemaValidator::TYPE_DATETIME_UPDATE
|
109
|
+
].include?(type)
|
110
|
+
import_statements << 'import java.time.ZonedDateTime;'
|
111
|
+
import_statements << 'import org.blufin.base.annotations.Transient;'
|
112
|
+
# special_instance_variable << '' unless instance_variables.last == ''
|
113
|
+
special_instance_variable << ' @Transient'
|
114
|
+
special_instance_variable << " private ZonedDateTime #{field_camel_case_lower};"
|
115
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_DATE
|
116
|
+
type = 'LocalDate'
|
117
|
+
import_statements << 'import java.time.LocalDate;'
|
118
|
+
elsif type =~ Blufin::YmlSchemaValidator::REGEX_DECIMAL
|
119
|
+
type = 'BigDecimal'
|
120
|
+
import_statements << 'import java.math.BigDecimal;'
|
121
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_INT_TINY
|
122
|
+
type = 'Byte'
|
123
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_INT_SMALL
|
124
|
+
type = 'Short'
|
125
|
+
elsif type == Blufin::YmlSchemaValidator::TYPE_INT_BIG
|
126
|
+
type = 'Long'
|
127
|
+
elsif [Blufin::YmlSchemaValidator::TYPE_INT, Blufin::YmlSchemaValidator::TYPE_INT_AUTO].include?(type)
|
128
|
+
type = 'Integer'
|
129
|
+
elsif [Blufin::YmlSchemaValidator::TYPE_TEXT, Blufin::YmlSchemaValidator::TYPE_TEXT_LONG].include?(type)
|
130
|
+
type = 'String'
|
131
|
+
elsif type == Blufin::ScannerJavaEmbeddedObjects::OBJECT
|
132
|
+
import_statements << 'import org.blufin.base.annotations.Transient;'
|
133
|
+
# special_instance_variable << '' unless instance_variables.last == ''
|
134
|
+
special_instance_variable << ' @Transient'
|
135
|
+
special_instance_variable << " private #{Blufin::Strings::snake_case_to_camel_case(column_data[Blufin::YmlSchemaValidator::TRANSIENT][1])} #{field_camel_case_lower};"
|
136
|
+
# special_instance_variable << ''
|
137
|
+
elsif type =~ Blufin::YmlSchemaValidator::REGEX_ENUM
|
138
|
+
enum_class_name = "#{class_name}#{field_camel_case}"
|
139
|
+
import_statements << "import #{get_package(@site, schema, Blufin::YmlJavaEnumWriter::PACKAGE_AUTO, SERVICE)}.#{enum_class_name};"
|
140
|
+
type = enum_class_name
|
141
|
+
elsif type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_CUSTOM
|
142
|
+
enum_class_name = Blufin::YmlCommon::enum_name_extractor(type)
|
143
|
+
import_statements << "import #{get_package(@site, schema, Blufin::YmlJavaEnumWriter::PACKAGE_CUSTOM, SERVICE)}.#{enum_class_name};"
|
144
|
+
type = enum_class_name
|
145
|
+
elsif type =~ Blufin::YmlSchemaValidator::REGEX_ENUM_SYSTEM
|
146
|
+
enum_class_name = Blufin::YmlCommon::enum_name_extractor(type)
|
147
|
+
import_statements << "import #{Blufin::SiteServices::PACKAGE_SYSTEM_ENUMS}.#{enum_class_name};"
|
148
|
+
type = enum_class_name
|
149
|
+
elsif type =~ Blufin::YmlSchemaValidator::REGEX_VARCHAR
|
150
|
+
type = 'String'
|
151
|
+
else
|
152
|
+
raise RuntimeError, "Unrecognized type in #{__FILE__}: #{type}"
|
153
|
+
end
|
154
|
+
|
155
|
+
if special_instance_variable.length > 0
|
156
|
+
special_instance_variable.each { |n| instance_variables << n }
|
157
|
+
else
|
158
|
+
instance_variables << " private #{type} #{field_camel_case_lower};#{write_column_description(column_data)}"
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
import_statements.uniq!
|
164
|
+
import_statements.sort!
|
165
|
+
|
166
|
+
content = [
|
167
|
+
"package #{get_package(@site, schema, PACKAGE, SERVICE)};",
|
168
|
+
'import com.fasterxml.jackson.annotation.JsonIgnore;',
|
169
|
+
'import org.blufin.sdk.base.PersistentDto;'
|
170
|
+
]
|
171
|
+
|
172
|
+
import_statements << 'import lombok.Data;'
|
173
|
+
import_statements << 'import lombok.NoArgsConstructor;'
|
174
|
+
|
175
|
+
if import_statements.any?
|
176
|
+
content = content.push(*import_statements)
|
177
|
+
content << ''
|
178
|
+
end
|
179
|
+
|
180
|
+
resource_hash = @schema_resources["#{schema}.#{table}"]
|
181
|
+
resource_type = resource_hash[:type]
|
182
|
+
|
183
|
+
parent_element = nil
|
184
|
+
|
185
|
+
if resource_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_PARENT
|
186
|
+
|
187
|
+
# DO NOTHING (for now)
|
188
|
+
|
189
|
+
elsif resource_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT || resource_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LIST
|
190
|
+
|
191
|
+
raise RuntimeError, "resource_hash[:tree].length is less than 2. Something is not right \xe2\x86\x92 #{resource_hash[:tree].inspect}" if resource_hash[:tree].length < 2
|
192
|
+
parent_element = Blufin::Strings::snake_case_to_camel_case_lower(resource_hash[:tree][resource_hash[:tree].length - 2])
|
193
|
+
|
194
|
+
elsif resource_type == Blufin::YmlSchemaValidator::RESOURCE_TYPE_OBJECT_LINK
|
195
|
+
|
196
|
+
# TODO - CANNOT BE NIL ... BUT WHY? 22/12/2015 ... STILL HAVEN'T LOOKED INTO THIS -> 02/18/2017
|
197
|
+
parent_element = nil
|
198
|
+
|
199
|
+
else
|
200
|
+
raise RuntimeError, "Unrecognized type: #{resource_type}"
|
201
|
+
end
|
202
|
+
|
203
|
+
content << '@Data'
|
204
|
+
content << '@NoArgsConstructor'
|
205
|
+
content << "public final class #{class_name} extends PersistentDto {"
|
206
|
+
content << ''
|
207
|
+
content = content.push(*instance_variables)
|
208
|
+
content = content.push(*special_getters) if special_getters.length > 0
|
209
|
+
unless parent_element.nil?
|
210
|
+
content << ''
|
211
|
+
content << ' @Override'
|
212
|
+
content << ' @JsonIgnore'
|
213
|
+
content << ' public Integer getParentId() {'
|
214
|
+
content << ''
|
215
|
+
content << " return this.#{parent_element}Id;"
|
216
|
+
content << ' }'
|
217
|
+
content << ''
|
218
|
+
content << ' @Override'
|
219
|
+
content << ' @JsonIgnore'
|
220
|
+
content << ' public void setParentId(Integer id) {'
|
221
|
+
content << ''
|
222
|
+
content << " this.#{parent_element}Id = id;"
|
223
|
+
content << ' }'
|
224
|
+
end
|
225
|
+
content << '}'
|
226
|
+
|
227
|
+
full_file_path = "#{get_java_path(@site, schema, SERVICE, PACKAGE)}/#{class_name}.java"
|
228
|
+
|
229
|
+
write_file_java(full_file_path, content, schema == Blufin::YmlSchemaValidator::MOCK).gsub(@site_location, '')
|
230
|
+
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
private
|
240
|
+
|
241
|
+
def write_column_description(column_data)
|
242
|
+
|
243
|
+
if !column_data.nil? && !column_data[Blufin::YmlSchemaValidator::DESCRIPTION].nil?
|
244
|
+
" /* #{Blufin::YmlCommon::description_without_formatting(column_data[Blufin::YmlSchemaValidator::DESCRIPTION])} */"
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|