smartclient 0.0.4 → 0.0.5
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/DSResponse.rb +2 -1
- data/lib/DataSource.rb +9 -12
- data/lib/RPCManager.rb +103 -14
- metadata +6 -6
data/lib/DSResponse.rb
CHANGED
data/lib/DataSource.rb
CHANGED
@@ -21,7 +21,7 @@ class DataSource
|
|
21
21
|
ds_content['isc.RestDataSource.create('] = ''
|
22
22
|
ds_content[');'] = ''
|
23
23
|
#remove tab, newline tag \n \r \t etc
|
24
|
-
result = ds_content
|
24
|
+
result = ds_content
|
25
25
|
return JSON.parse(result)
|
26
26
|
end
|
27
27
|
=begin
|
@@ -81,20 +81,18 @@ private
|
|
81
81
|
response.status = 0
|
82
82
|
response.totalRow = objs_count
|
83
83
|
|
84
|
-
|
85
|
-
return @result
|
84
|
+
return response
|
86
85
|
end
|
87
86
|
=begin
|
88
87
|
<summary>Add new item</summary>
|
89
88
|
=end
|
90
89
|
def add(request)
|
91
90
|
new_data = request.data
|
92
|
-
new_supplyitem = @model.create(new_data)
|
91
|
+
new_supplyitem = @model.create(new_data)
|
93
92
|
response = DSResponse.new
|
94
93
|
response.data = new_data
|
95
|
-
response.status = 0
|
96
|
-
|
97
|
-
return @result
|
94
|
+
response.status = 0
|
95
|
+
return response
|
98
96
|
end
|
99
97
|
=begin
|
100
98
|
<summary>Remove the selected item</summary>
|
@@ -103,12 +101,11 @@ private
|
|
103
101
|
data = request.data
|
104
102
|
item_id = data['itemID']
|
105
103
|
# remove the item
|
106
|
-
@model.destroy(item_id)
|
104
|
+
@model.destroy(item_id)
|
107
105
|
response = DSResponse.new
|
108
106
|
response.data = data
|
109
|
-
response.status = 0
|
110
|
-
|
111
|
-
return @result
|
107
|
+
response.status = 0
|
108
|
+
return response
|
112
109
|
end
|
113
110
|
=begin
|
114
111
|
<summary>Update the items</summary>
|
@@ -124,7 +121,7 @@ private
|
|
124
121
|
merged_data.delete('itemID')
|
125
122
|
|
126
123
|
#update
|
127
|
-
@model.update(item_id, merged_data)
|
124
|
+
@model.update(item_id, merged_data)
|
128
125
|
return nil
|
129
126
|
end
|
130
127
|
end
|
data/lib/RPCManager.rb
CHANGED
@@ -12,6 +12,7 @@ require 'DSResponse'
|
|
12
12
|
class RPCManager
|
13
13
|
@request = nil
|
14
14
|
@model = nil
|
15
|
+
@temp_request = nil
|
15
16
|
=begin
|
16
17
|
<summary>
|
17
18
|
Process the request with the model.
|
@@ -22,10 +23,34 @@ class RPCManager
|
|
22
23
|
model: the object that is mapped to the table
|
23
24
|
</params>
|
24
25
|
=end
|
25
|
-
def initialize(request=nil, model=nil)
|
26
|
-
@
|
27
|
-
|
26
|
+
def initialize(request=nil, model=nil)
|
27
|
+
@model = model
|
28
|
+
# if is not wrapped in a transaction then we'll wrap it to make unified handling of the request
|
29
|
+
if !check_transaction(request)
|
30
|
+
req_hash = HashWithIndifferentAccess.new
|
31
|
+
req_hash[:transaction] = HashWithIndifferentAccess.new
|
32
|
+
req_hash[:transaction][:transactionNum] = -1
|
33
|
+
req_list = Array.new
|
34
|
+
req_list << request
|
35
|
+
req_hash[:transaction][:operations] = req_list
|
36
|
+
@request = req_hash
|
37
|
+
else
|
38
|
+
@request = request
|
39
|
+
end
|
28
40
|
end
|
41
|
+
=begin
|
42
|
+
<summary>
|
43
|
+
Returns true if the request has transaction support
|
44
|
+
</summary>
|
45
|
+
<returns></returns>
|
46
|
+
=end
|
47
|
+
def check_transaction(request)
|
48
|
+
if request.include?(:transaction)# and request.include?(:operations) and request.include?(:transactionNum)
|
49
|
+
return true
|
50
|
+
else
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
end
|
29
54
|
=begin
|
30
55
|
<summary>
|
31
56
|
Transforms a object object into a Json. Will setup the serializer with the
|
@@ -35,16 +60,80 @@ class RPCManager
|
|
35
60
|
<returns>the created json object</returns>
|
36
61
|
=end
|
37
62
|
def processRequest
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
res = req.execute
|
42
|
-
|
43
|
-
# safeguard, if was null, create an empty response with failed status
|
44
|
-
if res.nil?
|
45
|
-
res = DSResponse.new
|
46
|
-
res.status=-1
|
47
|
-
end
|
48
|
-
return res
|
63
|
+
response = processTransaction
|
64
|
+
@result = { :response => response }
|
65
|
+
return @result
|
49
66
|
end
|
67
|
+
=begin
|
68
|
+
<summary>
|
69
|
+
Process the transaction request for which this RPCManager was created for
|
70
|
+
</summary>
|
71
|
+
<returns></returns>
|
72
|
+
=end
|
73
|
+
def processTransaction
|
74
|
+
# retrieve the requests with data in form
|
75
|
+
transaction_request = @request[:transaction]
|
76
|
+
# store transaction num, we'll use it later to see if there was a transaction or not
|
77
|
+
transaction_num = transaction_request[:transactionNum]
|
78
|
+
# fetch the operations
|
79
|
+
operations = transaction_request[:operations]
|
80
|
+
|
81
|
+
queueFailed = false
|
82
|
+
# response list
|
83
|
+
res_list = Array.new
|
84
|
+
# transaction progress
|
85
|
+
@model.transaction do
|
86
|
+
begin
|
87
|
+
operations.each do |op|
|
88
|
+
|
89
|
+
req = DSRequest.new(op, @model)
|
90
|
+
# execute the request and get the response
|
91
|
+
res = req.execute
|
92
|
+
if res == nil
|
93
|
+
res = DSResponse.new
|
94
|
+
res.status = -1
|
95
|
+
end
|
96
|
+
|
97
|
+
# if request execution failed, mark the flag variable
|
98
|
+
if res.status == -1
|
99
|
+
queueFailed = true
|
100
|
+
end
|
101
|
+
|
102
|
+
# store the response for later
|
103
|
+
res_list << res
|
104
|
+
end
|
105
|
+
rescue ActiveRecord::RecordInvalid
|
106
|
+
# if it occurs exception
|
107
|
+
raise ActiveRecord::Rollback
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# if we have only one object, send directly the DSResponse
|
112
|
+
if transaction_num == -1
|
113
|
+
response = DSResponse.new
|
114
|
+
response.data = res_list[0].data
|
115
|
+
response.startRow = res_list[0].startRow
|
116
|
+
response.endRow = res_list[0].endRow
|
117
|
+
response.totalRow = res_list[0].totalRow
|
118
|
+
response.status = res_list[0].status
|
119
|
+
|
120
|
+
return response
|
121
|
+
end
|
122
|
+
|
123
|
+
# iterate over the responses and create a instance of an anonymous class which mimics the required json
|
124
|
+
responses = Array.new
|
125
|
+
|
126
|
+
res_list.each do | response |
|
127
|
+
|
128
|
+
res = DSResponse.new
|
129
|
+
res.data = response.data
|
130
|
+
res.startRow = response.startRow
|
131
|
+
res.endRow = response.endRow
|
132
|
+
res.totalRow = response.totalRow
|
133
|
+
res.status = response.status
|
134
|
+
|
135
|
+
responses << res
|
136
|
+
end
|
137
|
+
return responses
|
138
|
+
end
|
50
139
|
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: ! "This gem will work for the smartclient.
|
15
|
-
you install this gem, you should define the filter
|
16
|
-
do this you need to copy the filter
|
17
|
-
directory to the model class."
|
14
|
+
description: ! "This gem will work for the smartclient. The transaction method was
|
15
|
+
added.\n\t After you install this gem, you should define the filter
|
16
|
+
method in the models.\n\t To do this you need to copy the filter
|
17
|
+
method of the filter.rb of the gem/smartclient directory to the model class."
|
18
18
|
email: kris.jin81@gmail.com
|
19
19
|
executables: []
|
20
20
|
extensions: []
|