smartclient 0.0.5 → 0.0.6
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.
- data/lib/DSRequest.rb +6 -2
- data/lib/DataSource.rb +279 -22
- data/lib/RPCManager.rb +27 -0
- metadata +7 -8
- data/lib/filter.rb +0 -32
data/lib/DSRequest.rb
CHANGED
@@ -7,7 +7,7 @@ require 'DataSource'
|
|
7
7
|
</summary>
|
8
8
|
=end
|
9
9
|
class DSRequest
|
10
|
-
attr_accessor :dataSource, :operationType, :startRow, :endRow, :textMatchStyle, :data, :sortBy, :oldValues
|
10
|
+
attr_accessor :dataSource, :operationType, :startRow, :endRow, :textMatchStyle, :data, :sortBy, :oldValues, :advancedCriteria
|
11
11
|
|
12
12
|
@dataSource = nil
|
13
13
|
@operationType = nil
|
@@ -18,7 +18,7 @@ class DSRequest
|
|
18
18
|
@data = nil
|
19
19
|
@sortBy = nil
|
20
20
|
@oldValues = nil
|
21
|
-
|
21
|
+
@advancedCriteria = nil
|
22
22
|
@@obj = nil
|
23
23
|
def initialize(data, model)
|
24
24
|
@componentId = data[:componentId]
|
@@ -51,5 +51,9 @@ class DSRequest
|
|
51
51
|
return ds.execute(self)
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
def advancedCriteria=(value)
|
56
|
+
@advancedCriteria = value
|
57
|
+
end
|
54
58
|
end
|
55
59
|
|
data/lib/DataSource.rb
CHANGED
@@ -56,32 +56,287 @@ class DataSource
|
|
56
56
|
end
|
57
57
|
|
58
58
|
private
|
59
|
+
def buildStandardCriteria(request, table_name)
|
60
|
+
query = 'SELECT * FROM ' + table_name + ' WHERE '
|
61
|
+
param = Array.new
|
62
|
+
condition = ''
|
63
|
+
request.data.each do |key, value|
|
64
|
+
condition += "#{key} LIKE ? AND "
|
65
|
+
param << "%" + value + "%"
|
66
|
+
end
|
67
|
+
q = condition[0, condition.rindex('AND ')]
|
68
|
+
query += q
|
69
|
+
|
70
|
+
order = ''
|
71
|
+
unless request.sortBy.nil?
|
72
|
+
request.sortBy.each do |idx|
|
73
|
+
if idx.index('-') === nil
|
74
|
+
order = " ORDER BY " + idx.to_s + " ASC"
|
75
|
+
else
|
76
|
+
order = " ORDER BY " + idx.to_s + " DESC"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
query += order
|
82
|
+
temp = Array.new
|
83
|
+
temp << query
|
84
|
+
temp.concat(param)
|
85
|
+
return temp
|
86
|
+
end
|
87
|
+
|
88
|
+
def buildAdvancedCriteria(request, table)
|
89
|
+
advancedCriteria = request.advancedCriteria
|
90
|
+
criteria_query = buildCriterion(advancedCriteria)
|
91
|
+
query = "SELECT * FROM " + table.to_s + " WHERE " + criteria_query[:query]
|
92
|
+
|
93
|
+
# sort by
|
94
|
+
order = ''
|
95
|
+
unless request.sortBy.nil?
|
96
|
+
request.sortBy.each do |idx|
|
97
|
+
if idx.index('-') === nil
|
98
|
+
order = " ORDER BY " + idx.to_s + " ASC"
|
99
|
+
else
|
100
|
+
order = " ORDER BY " + idx.to_s + " DESC"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
query += order
|
105
|
+
|
106
|
+
result = Array.new
|
107
|
+
result << query
|
108
|
+
result.concat(criteria_query[:values])
|
109
|
+
|
110
|
+
Rails.logger.info('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
|
111
|
+
Rails.logger.info(result)
|
112
|
+
Rails.logger.info('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
|
113
|
+
return result
|
114
|
+
end
|
115
|
+
|
116
|
+
def buildCriterion(advancedCriteria)
|
117
|
+
criterias = advancedCriteria[:criteria]
|
118
|
+
|
119
|
+
operator = advancedCriteria[:operator]
|
120
|
+
values = Array.new
|
121
|
+
result = ''
|
122
|
+
criterias.each do | c |
|
123
|
+
if c.has_key?(:fieldName)
|
124
|
+
fn = c[:fieldName]
|
125
|
+
end
|
126
|
+
|
127
|
+
if c.has_key?(:operator)
|
128
|
+
op = c[:operator]
|
129
|
+
end
|
130
|
+
|
131
|
+
if c.has_key?(:value)
|
132
|
+
if c[:value] === true
|
133
|
+
val = 1
|
134
|
+
elsif c[:value] === false
|
135
|
+
val = 0
|
136
|
+
else
|
137
|
+
val = c[:value]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
if c.has_key?(:start)
|
142
|
+
start = c[:start]
|
143
|
+
end
|
144
|
+
|
145
|
+
if c.has_key?(:end)
|
146
|
+
_end = c[:end]
|
147
|
+
end
|
148
|
+
|
149
|
+
if c.has_key?(:criteria)
|
150
|
+
criteria = c[:criteria]
|
151
|
+
else
|
152
|
+
criteria = nil
|
153
|
+
end
|
154
|
+
|
155
|
+
if criteria == nil
|
156
|
+
query = ''
|
157
|
+
case op
|
158
|
+
when 'equals'
|
159
|
+
query = "#{fn} = ?";
|
160
|
+
values << val
|
161
|
+
|
162
|
+
when 'notEqual'
|
163
|
+
query = "#{fn} != ?";
|
164
|
+
values << val
|
165
|
+
|
166
|
+
when 'iEquals'
|
167
|
+
query = "UPPER(#{fn}) = ?"
|
168
|
+
values << "UPPER('#{val}')"
|
169
|
+
|
170
|
+
when 'iNotEqual'
|
171
|
+
query = "UPPER(#{fn}) != ?"
|
172
|
+
values << "UPPER('#{val}')"
|
173
|
+
|
174
|
+
when 'greaterThan'
|
175
|
+
query = "#{fn} > ?"
|
176
|
+
values << val
|
177
|
+
|
178
|
+
when 'lessThan'
|
179
|
+
query = "#{fn} < ?"
|
180
|
+
values << val
|
181
|
+
|
182
|
+
when 'greaterOrEqual'
|
183
|
+
query = "#{fn} >= ?"
|
184
|
+
values << val
|
185
|
+
|
186
|
+
when 'lessOrEqual'
|
187
|
+
query = "#{fn} <= ?";
|
188
|
+
values << val
|
189
|
+
|
190
|
+
when 'contains'
|
191
|
+
query = "#{fn} LIKE ?";
|
192
|
+
values << "%#{val}%"
|
193
|
+
|
194
|
+
when 'startsWith'
|
195
|
+
query = "#{fn} LIKE ?";
|
196
|
+
values << "#{val}%"
|
197
|
+
|
198
|
+
when 'endsWith'
|
199
|
+
query = "#{fn} LIKE ?";
|
200
|
+
values << "%#{val}"
|
201
|
+
|
202
|
+
when 'iContains'
|
203
|
+
query = "#{fn} LIKE ?";
|
204
|
+
values << "%#{val}%"
|
205
|
+
|
206
|
+
when 'iStartsWith'
|
207
|
+
query = "UPPER(#{fn}) LIKE ?"
|
208
|
+
values << "UPPER('#{val}%')"
|
209
|
+
|
210
|
+
when 'iEndsWith'
|
211
|
+
query = "UPPER(#{fn}) LIKE ?"
|
212
|
+
values << "UPPER('%#{val}')"
|
213
|
+
|
214
|
+
when 'notContains'
|
215
|
+
query = "#{fn} NOT LIKE ?"
|
216
|
+
values << "%#{val}%"
|
217
|
+
|
218
|
+
when 'notStartsWith'
|
219
|
+
query = "#{fn} NOT LIKE ?"
|
220
|
+
values << "#{val}%"
|
221
|
+
|
222
|
+
when 'notEndsWith'
|
223
|
+
query = "#{fn} NOT LIKE ?"
|
224
|
+
values << "%#{val}"
|
225
|
+
|
226
|
+
when 'iNotContains'
|
227
|
+
query = "UPPER(#{fn}) NOT LIKE ?"
|
228
|
+
values << "UPPER('%#{val}%')"
|
229
|
+
|
230
|
+
when 'iNotStartsWith'
|
231
|
+
query = "UPPER(#{fn}) NOT LIKE ?"
|
232
|
+
values << "UPPER('#{val}%')"
|
233
|
+
|
234
|
+
when 'iNotEndsWith'
|
235
|
+
query = "UPPER(#{fn}) NOT LIKE ?"
|
236
|
+
values << "UPPER('%#{val}')"
|
237
|
+
|
238
|
+
when 'isNull'
|
239
|
+
query = "#{fn} IS NULL"
|
240
|
+
|
241
|
+
when 'notNull'
|
242
|
+
query = "#{fn} IS NOT NULL"
|
243
|
+
|
244
|
+
when 'equalsField'
|
245
|
+
query = "#{fn} LIKE ?"
|
246
|
+
values << "CONCAT('#{val}', '%')"
|
247
|
+
|
248
|
+
when 'iEqualsField'
|
249
|
+
query = "UPPER(#{fn}) LIKE ?"
|
250
|
+
values << "UPPER(CONCAT('#{val}', '%'))"
|
251
|
+
|
252
|
+
when 'iNotEqualField'
|
253
|
+
query = "UPPER(#{fn}) NOT LIKE ?"
|
254
|
+
values << "UPPER(CONCAT('#{val}', '%'))"
|
255
|
+
|
256
|
+
when 'notEqualField'
|
257
|
+
query = "#{fn} NOT LIKE ?"
|
258
|
+
values << "CONCAT('#{val}', '%')"
|
259
|
+
|
260
|
+
when 'greaterThanField'
|
261
|
+
query = "#{fn} > ?"
|
262
|
+
values << "CONCAT('#{val}', '%')"
|
263
|
+
|
264
|
+
when 'lessThanField'
|
265
|
+
query = "#{fn} < ?"
|
266
|
+
values << "CONCAT('#{val}', '%')"
|
267
|
+
|
268
|
+
when 'greaterOrEqualField'
|
269
|
+
query = "#{fn} >= ?"
|
270
|
+
values << "CONCAT('#{val}', '%')"
|
271
|
+
|
272
|
+
when 'lessOrEqualField'
|
273
|
+
query = "#{fn} <= ?"
|
274
|
+
values << "CONCAT('#{val}', '%')"
|
275
|
+
|
276
|
+
when 'iBetweenInclusive'
|
277
|
+
query = "#{fn} BETWEEM ? AND ?"
|
278
|
+
values << start
|
279
|
+
values << _end
|
280
|
+
|
281
|
+
when 'betweenInclusive'
|
282
|
+
query = "#{fn} BETWEEM ? AND ?"
|
283
|
+
values << start
|
284
|
+
values << _end
|
285
|
+
|
286
|
+
end
|
287
|
+
result = result.to_s + " " + query.to_s + " " + operator.to_s + " "
|
288
|
+
else
|
289
|
+
# build the list of subcriterias or criterions
|
290
|
+
temp = result
|
291
|
+
result1 = buildCriterion(c)
|
292
|
+
result = temp.to_s + "(" + result1[:query] + ") " + operator + " "
|
293
|
+
|
294
|
+
result1[:values].each do | value |
|
295
|
+
values << value
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
q = result[0, result.rindex(operator)]
|
301
|
+
|
302
|
+
criteria_result = Hash.new
|
303
|
+
criteria_result[:query] = q
|
304
|
+
criteria_result[:values] = values
|
305
|
+
|
306
|
+
return criteria_result
|
307
|
+
end
|
59
308
|
=begin
|
60
309
|
<summary> get the item list from the table </summary>
|
61
310
|
<note>Before this method is called, the filter method should define in the model of the projects.</note>
|
62
311
|
=end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
312
|
+
def fetch(request)
|
313
|
+
table_name = @model.table_name
|
314
|
+
data = request.data
|
315
|
+
# check the advanced cretira
|
316
|
+
unless request.advancedCriteria.nil?
|
317
|
+
query = buildAdvancedCriteria(request, table_name)
|
318
|
+
@obj_items = @model.find_by_sql(query)
|
319
|
+
else
|
320
|
+
unless request.data.empty?
|
321
|
+
query = buildStandardCriteria(request, table_name)
|
322
|
+
@obj_items = @model.find_by_sql(query)
|
323
|
+
else
|
324
|
+
@obj_items = @model.find(:all)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
objs_count = @obj_items.count
|
328
|
+
# get the count of the obj_items
|
329
|
+
endRow = (objs_count > 0)?objs_count - 1 : objs_count
|
71
330
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
response.status = 0
|
82
|
-
response.totalRow = objs_count
|
83
|
-
|
84
|
-
return response
|
331
|
+
# make the Response result object
|
332
|
+
response = DSResponse.new
|
333
|
+
response.data = @obj_items
|
334
|
+
response.startRow = 0
|
335
|
+
response.endRow = endRow
|
336
|
+
response.status = 0
|
337
|
+
response.totalRow = objs_count
|
338
|
+
|
339
|
+
return response
|
85
340
|
end
|
86
341
|
=begin
|
87
342
|
<summary>Add new item</summary>
|
@@ -122,6 +377,8 @@ private
|
|
122
377
|
|
123
378
|
#update
|
124
379
|
@model.update(item_id, merged_data)
|
125
|
-
|
380
|
+
response = DSResponse.new
|
381
|
+
response.status = 0
|
382
|
+
return response
|
126
383
|
end
|
127
384
|
end
|
data/lib/RPCManager.rb
CHANGED
@@ -38,6 +38,20 @@ class RPCManager
|
|
38
38
|
@request = request
|
39
39
|
end
|
40
40
|
end
|
41
|
+
=begin
|
42
|
+
<summary>
|
43
|
+
Helper method to decide if request contains an advanced criteria or not
|
44
|
+
</summary>
|
45
|
+
<param name="req"></param>
|
46
|
+
<returns></returns>
|
47
|
+
=end
|
48
|
+
def check_advanced_criteria(data)
|
49
|
+
if data.include?(:_constructor)
|
50
|
+
return true
|
51
|
+
else
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
end
|
41
55
|
=begin
|
42
56
|
<summary>
|
43
57
|
Returns true if the request has transaction support
|
@@ -85,8 +99,13 @@ class RPCManager
|
|
85
99
|
@model.transaction do
|
86
100
|
begin
|
87
101
|
operations.each do |op|
|
102
|
+
# parase advanced criterias, if any
|
103
|
+
advanced_criteria = parse_advanced_criterias(op)
|
88
104
|
|
89
105
|
req = DSRequest.new(op, @model)
|
106
|
+
unless advanced_criteria == nil
|
107
|
+
req.advancedCriteria = advanced_criteria
|
108
|
+
end
|
90
109
|
# execute the request and get the response
|
91
110
|
res = req.execute
|
92
111
|
if res == nil
|
@@ -136,4 +155,12 @@ class RPCManager
|
|
136
155
|
end
|
137
156
|
return responses
|
138
157
|
end
|
158
|
+
|
159
|
+
def parse_advanced_criterias(operations)
|
160
|
+
data = operations[:data]
|
161
|
+
if check_advanced_criteria(data)
|
162
|
+
return data
|
163
|
+
end
|
164
|
+
return nil
|
165
|
+
end
|
139
166
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: ! "
|
15
|
-
|
16
|
-
|
17
|
-
method of the filter.rb of the gem/smartclient directory to the model class."
|
14
|
+
description: ! "SmartClient combines the industry's richest set of cross-browser UI
|
15
|
+
components with a Java server framework to provide an end-to-end solution for building
|
16
|
+
business web applications\n\t\t\t\t\t\tThis gem will work for the smartclient."
|
18
17
|
email: kris.jin81@gmail.com
|
19
18
|
executables: []
|
20
19
|
extensions: []
|
@@ -24,7 +23,6 @@ files:
|
|
24
23
|
- lib/DSRequest.rb
|
25
24
|
- lib/DSResponse.rb
|
26
25
|
- lib/DataSource.rb
|
27
|
-
- lib/filter.rb
|
28
26
|
homepage: http://smartclient.com/
|
29
27
|
licenses: []
|
30
28
|
post_install_message:
|
@@ -48,5 +46,6 @@ rubyforge_project:
|
|
48
46
|
rubygems_version: 1.8.11
|
49
47
|
signing_key:
|
50
48
|
specification_version: 3
|
51
|
-
summary: It supports the request and response class
|
49
|
+
summary: It supports the request and response class and the RPCManager helper class
|
50
|
+
for the smartclient. It also supports for advanced cretirea filtering method.
|
52
51
|
test_files: []
|
data/lib/filter.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
def self.filter(request)
|
2
|
-
param = Array.new
|
3
|
-
condition = ''
|
4
|
-
request.data.each do |key, value|
|
5
|
-
condition += "#{key} LIKE ? AND "
|
6
|
-
param << "%" + value + "%"
|
7
|
-
end
|
8
|
-
q = condition[0, condition.rindex('AND ')]
|
9
|
-
temp = Array.new
|
10
|
-
temp << q
|
11
|
-
temp.concat(param)
|
12
|
-
where(temp)
|
13
|
-
order = ''
|
14
|
-
# sort by
|
15
|
-
unless request.sortBy.nil?
|
16
|
-
request.sortBy.each do |idx|
|
17
|
-
if idx.index('-') === nil
|
18
|
-
order = idx.to_s + " ASC"
|
19
|
-
else
|
20
|
-
order = idx.to_s + " DESC"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
# return the result
|
25
|
-
|
26
|
-
|
27
|
-
if order == nil
|
28
|
-
where(temp)
|
29
|
-
else
|
30
|
-
where(temp).order(order)
|
31
|
-
end
|
32
|
-
end
|