smartclient 0.0.6 → 0.0.7

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.
Files changed (3) hide show
  1. data/lib/DataSource.rb +14 -27
  2. data/lib/RPCManager.rb +24 -14
  3. metadata +2 -2
data/lib/DataSource.rb CHANGED
@@ -8,21 +8,10 @@ class DataSource
8
8
  attr_accessor :data_source
9
9
  @data_source = nil
10
10
  @model = nil
11
- def initialize(path, model)
12
- #@data_source = self.get_data(path)
11
+ @pk = nil
12
+ def initialize(path, model)
13
13
  @model = model
14
- end
15
- =begin
16
- <summary> get the DataSource contents from the path and parse to JSON format </summary>
17
- =end
18
- def get_data(path)
19
- ds_content = File.read(path)
20
- #remove the isc tag and the end tag
21
- ds_content['isc.RestDataSource.create('] = ''
22
- ds_content[');'] = ''
23
- #remove tab, newline tag \n \r \t etc
24
- result = ds_content
25
- return JSON.parse(result)
14
+ @pk = @model.primary_key()
26
15
  end
27
16
  =begin
28
17
  <summary> get the field content by the filed name </summary>
@@ -106,10 +95,7 @@ private
106
95
  result = Array.new
107
96
  result << query
108
97
  result.concat(criteria_query[:values])
109
-
110
- Rails.logger.info('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
111
- Rails.logger.info(result)
112
- Rails.logger.info('<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<')
98
+
113
99
  return result
114
100
  end
115
101
 
@@ -342,8 +328,8 @@ private
342
328
  <summary>Add new item</summary>
343
329
  =end
344
330
  def add(request)
345
- new_data = request.data
346
- new_supplyitem = @model.create(new_data)
331
+ new_data = request.data
332
+ @model.create(new_data)
347
333
  response = DSResponse.new
348
334
  response.data = new_data
349
335
  response.status = 0
@@ -353,12 +339,12 @@ private
353
339
  <summary>Remove the selected item</summary>
354
340
  =end
355
341
  def remove(request)
356
- data = request.data
357
- item_id = data['itemID']
342
+ data = request.data
343
+ id = data[@pk]
358
344
  # remove the item
359
- @model.destroy(item_id)
345
+ @model.destroy(id)
360
346
  response = DSResponse.new
361
- response.data = data
347
+ response.data = nil
362
348
  response.status = 0
363
349
  return response
364
350
  end
@@ -370,13 +356,14 @@ private
370
356
  old_data = request.oldValues
371
357
  # get the date from the request object
372
358
  update_data = request.data
373
- item_id = update_data['itemID']
359
+
360
+ new_id = update_data[@pk]
374
361
  # merge to hash objects
375
362
  merged_data = old_data.merge!(update_data)
376
- merged_data.delete('itemID')
363
+ merged_data.delete(@pk)
377
364
 
378
365
  #update
379
- @model.update(item_id, merged_data)
366
+ @model.update(new_id, merged_data)
380
367
  response = DSResponse.new
381
368
  response.status = 0
382
369
  return response
data/lib/RPCManager.rb CHANGED
@@ -23,8 +23,7 @@ class RPCManager
23
23
  model: the object that is mapped to the table
24
24
  </params>
25
25
  =end
26
- def initialize(request=nil, model=nil)
27
- @model = model
26
+ def initialize(request=nil)
28
27
  # if is not wrapped in a transaction then we'll wrap it to make unified handling of the request
29
28
  if !check_transaction(request)
30
29
  req_hash = HashWithIndifferentAccess.new
@@ -38,6 +37,10 @@ class RPCManager
38
37
  @request = request
39
38
  end
40
39
  end
40
+
41
+ def model=(model)
42
+ @model = model
43
+ end
41
44
  =begin
42
45
  <summary>
43
46
  Helper method to decide if request contains an advanced criteria or not
@@ -78,6 +81,19 @@ class RPCManager
78
81
  @result = { :response => response }
79
82
  return @result
80
83
  end
84
+ =begin
85
+ <summary>
86
+ Select the model by the datasource
87
+ </summary>
88
+ <returns>Datasource name</returns>
89
+ =end
90
+ def get_datasource
91
+ if @request.include?(:transaction)
92
+ return @request[:transaction][:operations][0][:dataSource]
93
+ else
94
+ return @request[:dataSource]
95
+ end
96
+ end
81
97
  =begin
82
98
  <summary>
83
99
  Process the transaction request for which this RPCManager was created for
@@ -92,16 +108,15 @@ class RPCManager
92
108
  # fetch the operations
93
109
  operations = transaction_request[:operations]
94
110
 
95
- queueFailed = false
96
111
  # response list
97
112
  res_list = Array.new
98
113
  # transaction progress
99
114
  @model.transaction do
100
115
  begin
101
- operations.each do |op|
116
+ operations.each do |op|
102
117
  # parase advanced criterias, if any
103
118
  advanced_criteria = parse_advanced_criterias(op)
104
-
119
+
105
120
  req = DSRequest.new(op, @model)
106
121
  unless advanced_criteria == nil
107
122
  req.advancedCriteria = advanced_criteria
@@ -113,13 +128,10 @@ class RPCManager
113
128
  res.status = -1
114
129
  end
115
130
 
116
- # if request execution failed, mark the flag variable
117
- if res.status == -1
118
- queueFailed = true
119
- end
131
+
120
132
 
121
133
  # store the response for later
122
- res_list << res
134
+ res_list << res
123
135
  end
124
136
  rescue ActiveRecord::RecordInvalid
125
137
  # if it occurs exception
@@ -142,15 +154,13 @@ class RPCManager
142
154
  # iterate over the responses and create a instance of an anonymous class which mimics the required json
143
155
  responses = Array.new
144
156
 
145
- res_list.each do | response |
146
-
157
+ res_list.each do | response |
147
158
  res = DSResponse.new
148
159
  res.data = response.data
149
160
  res.startRow = response.startRow
150
161
  res.endRow = response.endRow
151
162
  res.totalRow = response.totalRow
152
- res.status = response.status
153
-
163
+ res.status = response.status
154
164
  responses << res
155
165
  end
156
166
  return responses
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-20 00:00:00.000000000 Z
12
+ date: 2013-05-23 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "SmartClient combines the industry's richest set of cross-browser UI
15
15
  components with a Java server framework to provide an end-to-end solution for building