rhoconnect 3.2.1 → 3.3.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. data/CHANGELOG.md +24 -5
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +20 -20
  4. data/bench/benchapp/Gemfile +17 -20
  5. data/bench/benchapp/config.ru +2 -2
  6. data/bench/benchapp/settings/settings.yml +3 -3
  7. data/bench/blobapp/Gemfile +16 -13
  8. data/bench/blobapp/config.ru +2 -2
  9. data/bench/blobapp/settings/settings.yml +5 -3
  10. data/bench/lib/bench.rb +35 -32
  11. data/bench/lib/bench/session.rb +9 -1
  12. data/bench/scripts/blob_cud_script.rb +13 -17
  13. data/bench/scripts/cud_script.rb +11 -12
  14. data/bench/scripts/helpers.rb +5 -7
  15. data/bench/scripts/query_md_script.rb +18 -12
  16. data/bench/scripts/query_only_script.rb +19 -11
  17. data/bench/scripts/query_script.rb +17 -13
  18. data/bench/scripts/test_query_script.rb +46 -17
  19. data/bench/scripts/test_source_script.rb +7 -7
  20. data/commands/commands/dtach_commands/dtach_install.rb +44 -16
  21. data/commands/commands/rhoconnect/spec.rb +13 -9
  22. data/commands/commands/rhoconnect/version.rb +6 -0
  23. data/commands/execute.rb +10 -6
  24. data/doc/deploying.txt +75 -13
  25. data/doc/install.txt +3 -3
  26. data/doc/push-client-setup.txt +1 -1
  27. data/doc/rest-api.txt +4 -23
  28. data/doc/rhoconnect-redis-stack.txt +26 -7
  29. data/doc/settings.txt +9 -3
  30. data/examples/simple/Gemfile +3 -1
  31. data/examples/simple/application.rb +5 -0
  32. data/examples/simple/config.ru +3 -2
  33. data/examples/simple/my_server.rb +14 -0
  34. data/examples/simple/settings/settings.yml +1 -0
  35. data/generators/templates/application/Gemfile +4 -4
  36. data/generators/templates/application/application.rb +4 -0
  37. data/generators/templates/application/settings/settings.yml +4 -1
  38. data/installer/unix-like/create_texts.rb +39 -1
  39. data/installer/unix-like/rho_connect_install_constants.rb +1 -1
  40. data/installer/utils/package_upload/repos.rake +7 -5
  41. data/lib/rhoconnect.rb +3 -2
  42. data/lib/rhoconnect/api/app/ans_login.rb +3 -0
  43. data/lib/rhoconnect/api/app/bulk_data.rb +6 -0
  44. data/lib/rhoconnect/api/{source → app}/fast_delete.rb +1 -1
  45. data/lib/rhoconnect/api/{source → app}/fast_insert.rb +2 -2
  46. data/lib/rhoconnect/api/{source → app}/fast_update.rb +2 -2
  47. data/lib/rhoconnect/api/app/login.rb +5 -0
  48. data/lib/rhoconnect/api/{source → app}/push_deletes.rb +1 -1
  49. data/lib/rhoconnect/api/{source → app}/push_objects.rb +1 -1
  50. data/lib/rhoconnect/api/app/query.rb +4 -0
  51. data/lib/rhoconnect/api/app/queue_updates.rb +94 -0
  52. data/lib/rhoconnect/api/app/search.rb +4 -0
  53. data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -0
  54. data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -0
  55. data/lib/rhoconnect/api/client/create.rb +7 -0
  56. data/lib/rhoconnect/api/client/get_client_params.rb +2 -1
  57. data/lib/rhoconnect/api/client/list_client_docs.rb +2 -1
  58. data/lib/rhoconnect/api/client/register.rb +12 -0
  59. data/lib/rhoconnect/api/client/reset.rb +5 -0
  60. data/lib/rhoconnect/api/{source → readstate}/set_refresh_time.rb +2 -1
  61. data/lib/rhoconnect/api/source/get_source_params.rb +3 -2
  62. data/lib/rhoconnect/api/source/list_sources.rb +2 -1
  63. data/lib/rhoconnect/api/source/update_source_params.rb +3 -3
  64. data/lib/rhoconnect/api/store/get_db_doc.rb +4 -0
  65. data/lib/rhoconnect/api/store/set_db_doc.rb +7 -0
  66. data/lib/rhoconnect/api/system/get_adapter.rb +4 -0
  67. data/lib/rhoconnect/api/{admin → system}/get_license_info.rb +2 -1
  68. data/lib/rhoconnect/api/system/login.rb +15 -0
  69. data/lib/rhoconnect/api/{admin → system}/reset.rb +3 -2
  70. data/lib/rhoconnect/api/system/save_adapter.rb +4 -0
  71. data/lib/rhoconnect/api/{admin → system}/stats.rb +2 -1
  72. data/lib/rhoconnect/api/user/create_user.rb +2 -2
  73. data/lib/rhoconnect/api/user/delete_client.rb +6 -0
  74. data/lib/rhoconnect/api/user/delete_user.rb +2 -1
  75. data/lib/rhoconnect/api/user/list_clients.rb +4 -0
  76. data/lib/rhoconnect/api/user/list_source_docs.rb +11 -0
  77. data/lib/rhoconnect/api/user/list_users.rb +1 -1
  78. data/lib/rhoconnect/api/user/ping.rb +7 -0
  79. data/lib/rhoconnect/api/user/show_user.rb +3 -0
  80. data/lib/rhoconnect/api/user/update_user.rb +3 -2
  81. data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -0
  82. data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -0
  83. data/lib/rhoconnect/app.rb +12 -2
  84. data/lib/rhoconnect/async.rb +6 -10
  85. data/lib/rhoconnect/bulk_data/bulk_data.rb +4 -4
  86. data/lib/rhoconnect/client.rb +10 -9
  87. data/lib/rhoconnect/client_sync.rb +24 -19
  88. data/lib/rhoconnect/document.rb +18 -4
  89. data/lib/rhoconnect/graph_helper.rb +4 -2
  90. data/lib/rhoconnect/jobs/bulk_data_job.rb +1 -1
  91. data/lib/rhoconnect/jobs/ping_job.rb +39 -29
  92. data/lib/rhoconnect/middleware/admin_user.rb +23 -0
  93. data/lib/rhoconnect/middleware/body_content_type_parser.rb +35 -0
  94. data/lib/rhoconnect/{cors.rb → middleware/cors.rb} +1 -0
  95. data/lib/rhoconnect/middleware/current_app.rb +16 -0
  96. data/lib/rhoconnect/middleware/current_request.rb +16 -0
  97. data/lib/rhoconnect/middleware/current_user.rb +17 -0
  98. data/lib/rhoconnect/middleware/helpers.rb +105 -0
  99. data/lib/rhoconnect/middleware/login_required.rb +22 -0
  100. data/lib/rhoconnect/{stats/middleware.rb → middleware/stats.rb} +5 -3
  101. data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +58 -0
  102. data/lib/rhoconnect/ping.rb +1 -0
  103. data/lib/rhoconnect/ping/apple.rb +18 -16
  104. data/lib/rhoconnect/ping/blackberry.rb +9 -9
  105. data/lib/rhoconnect/ping/rhoconnect_push.rb +45 -0
  106. data/lib/rhoconnect/server.rb +98 -91
  107. data/lib/rhoconnect/source.rb +5 -1
  108. data/lib/rhoconnect/source_sync.rb +4 -3
  109. data/lib/rhoconnect/stats/record.rb +15 -15
  110. data/lib/rhoconnect/store.rb +253 -75
  111. data/lib/rhoconnect/tasks.rb +3 -3
  112. data/lib/rhoconnect/version.rb +1 -1
  113. data/lib/rhoconnect/web-console/controllers/admins.js +1 -14
  114. data/lib/rhoconnect/web-console/models/adapter.js +18 -8
  115. data/lib/rhoconnect/web-console/models/client.js +15 -9
  116. data/lib/rhoconnect/web-console/models/doc.js +7 -11
  117. data/lib/rhoconnect/web-console/models/session.js +5 -2
  118. data/lib/rhoconnect/web-console/models/source.js +55 -36
  119. data/lib/rhoconnect/web-console/models/user.js +20 -11
  120. data/lib/rhoconnect/web-console/public/backbone.js +8 -2
  121. data/lib/rhoconnect/web-console/templates/index.erb +11 -5
  122. data/lib/rhoconnect/web-console/views/doc.js +6 -8
  123. data/lib/rhoconnect/web-console/views/edit_user.js +6 -3
  124. data/lib/rhoconnect/web-console/views/home.js +98 -25
  125. data/lib/rhoconnect/web-console/views/index.js +1 -1
  126. data/lib/rhoconnect/web-console/views/new_ping.js +6 -3
  127. data/lib/rhoconnect/web-console/views/server_doc.js +12 -4
  128. data/lib/rhoconnect/web-console/views/show_device.js +6 -3
  129. data/rhoconnect.gemspec +1 -2
  130. data/spec/api/{source → app}/fast_delete_spec.rb +4 -4
  131. data/spec/api/{source → app}/fast_insert_spec.rb +4 -4
  132. data/spec/api/{source → app}/fast_update_spec.rb +22 -6
  133. data/spec/api/{source → app}/push_deletes_spec.rb +2 -2
  134. data/spec/api/app/push_objects_spec.rb +45 -0
  135. data/spec/api/client/client_get_db_doc_spec.rb +31 -0
  136. data/spec/api/client/client_set_db_doc_spec.rb +14 -0
  137. data/spec/api/client/get_client_params_spec.rb +3 -2
  138. data/spec/api/client/list_client_docs_spec.rb +2 -2
  139. data/spec/api/{source → readstate}/set_refresh_time_spec.rb +15 -9
  140. data/spec/api/source/get_source_params_spec.rb +3 -2
  141. data/spec/api/source/list_sources_spec.rb +3 -9
  142. data/spec/api/source/update_source_params_spec.rb +4 -4
  143. data/spec/api/store/get_db_doc_spec.rb +32 -0
  144. data/spec/api/store/set_db_doc_spec.rb +43 -0
  145. data/spec/api/system/adapter_spec.rb +33 -0
  146. data/spec/api/{admin → system}/get_license_info_spec.rb +2 -5
  147. data/spec/api/{admin/get_api_token_spec.rb → system/login_spec.rb} +4 -11
  148. data/spec/api/{admin → system}/reset_spec.rb +2 -2
  149. data/spec/api/{admin → system}/stats_spec.rb +19 -13
  150. data/spec/api/user/create_user_spec.rb +15 -8
  151. data/spec/api/{client → user}/delete_client_spec.rb +3 -4
  152. data/spec/api/user/delete_user_spec.rb +33 -4
  153. data/spec/api/user/list_clients_spec.rb +30 -0
  154. data/spec/api/user/list_source_docs_spec.rb +35 -0
  155. data/spec/api/user/list_users_spec.rb +5 -6
  156. data/spec/api/{client → user}/ping_spec.rb +4 -6
  157. data/spec/api/user/show_user_spec.rb +14 -0
  158. data/spec/api/user/update_user_spec.rb +28 -10
  159. data/spec/api/user/user_get_db_doc_spec.rb +16 -0
  160. data/spec/api/user/user_set_db_doc_spec.rb +41 -0
  161. data/spec/apps/rhotestapp/application.rb +4 -0
  162. data/spec/apps/rhotestapp/settings/settings.yml +3 -1
  163. data/spec/bulk_data/bulk_data_spec.rb +13 -0
  164. data/spec/client_sync_spec.rb +41 -59
  165. data/spec/document_spec.rb +23 -0
  166. data/spec/javascripts/doc_view_spec.js +1 -1
  167. data/spec/javascripts/home_view_spec.js +10 -5
  168. data/spec/javascripts/index_view_spec.js +1 -1
  169. data/spec/jobs/ping_job_spec.rb +26 -0
  170. data/spec/perf/store_perf_spec.rb +1 -1
  171. data/spec/ping/android_spec.rb +0 -7
  172. data/spec/ping/apple_spec.rb +7 -0
  173. data/spec/ping/blackberry_spec.rb +10 -0
  174. data/spec/ping/rhoconnect_push_spec.rb +58 -0
  175. data/spec/server/cors_spec.rb +1 -1
  176. data/spec/server/server_spec.rb +152 -104
  177. data/spec/{stats/middleware_spec.rb → server/stats_spec.rb} +4 -5
  178. data/spec/server/x_domain_session_wrapper_spec.rb +3 -3
  179. data/spec/source_spec.rb +2 -2
  180. data/spec/source_sync_spec.rb +2 -0
  181. data/spec/spec_helper.rb +17 -3
  182. data/spec/stats/record_spec.rb +18 -19
  183. data/spec/store_spec.rb +51 -26
  184. data/spec/support/shared_examples.rb +4 -0
  185. data/spec/sync_states_spec.rb +2 -2
  186. metadata +104 -88
  187. data/bench/benchapp/Gemfile.lock +0 -87
  188. data/bench/blobapp/Gemfile.lock +0 -107
  189. data/bench/lib/testdata/5-data.txt +0 -8
  190. data/doc/release.txt +0 -41
  191. data/lib/rhoconnect/api/admin/get_api_token.rb +0 -14
  192. data/lib/rhoconnect/api/admin/login.rb +0 -6
  193. data/lib/rhoconnect/api/application/bulk_data.rb +0 -7
  194. data/lib/rhoconnect/api/application/clientcreate.rb +0 -8
  195. data/lib/rhoconnect/api/application/clientlogin.rb +0 -6
  196. data/lib/rhoconnect/api/application/clientregister.rb +0 -13
  197. data/lib/rhoconnect/api/application/clientreset.rb +0 -6
  198. data/lib/rhoconnect/api/application/query.rb +0 -7
  199. data/lib/rhoconnect/api/application/queue_updates.rb +0 -20
  200. data/lib/rhoconnect/api/application/search.rb +0 -6
  201. data/lib/rhoconnect/api/client/create_client.rb +0 -3
  202. data/lib/rhoconnect/api/client/delete_client.rb +0 -5
  203. data/lib/rhoconnect/api/client/list_clients.rb +0 -3
  204. data/lib/rhoconnect/api/client/ping.rb +0 -7
  205. data/lib/rhoconnect/api/source/get_adapter.rb +0 -3
  206. data/lib/rhoconnect/api/source/get_db_doc.rb +0 -7
  207. data/lib/rhoconnect/api/source/list_source_docs.rb +0 -10
  208. data/lib/rhoconnect/api/source/save_adapter.rb +0 -3
  209. data/lib/rhoconnect/api/source/set_db_doc.rb +0 -10
  210. data/lib/rhoconnect/api/source/upload_file.rb +0 -4
  211. data/lib/rhoconnect/body_content_type_parser.rb +0 -32
  212. data/lib/rhoconnect/x_domain_session_wrapper.rb +0 -53
  213. data/spec/api/admin/api_token_spec.rb +0 -13
  214. data/spec/api/client/create_client_spec.rb +0 -13
  215. data/spec/api/client/list_clients_spec.rb +0 -22
  216. data/spec/api/source/adapter_spec.rb +0 -29
  217. data/spec/api/source/get_db_doc_spec.rb +0 -21
  218. data/spec/api/source/list_source_docs_spec.rb +0 -25
  219. data/spec/api/source/push_objects_spec.rb +0 -27
  220. data/spec/api/source/set_db_doc_spec.rb +0 -32
  221. data/spec/api/source/upload_file_spec.rb +0 -26
@@ -1,4 +1,5 @@
1
- Server.api :get_license_info, :admin do |params,user|
1
+ Server.api4 :get_license_info, :get, "/rc/#{Rhoconnect::API_VERSION}/system/license", \
2
+ true, {:verb => :post, :url => ['/api/get_license_info', '/api/admin/get_license_info']} do |params,user|
2
3
  {:rhoconnect_version => Rhoconnect.license.rhoconnect_version,
3
4
  :licensee => Rhoconnect.license.licensee,
4
5
  :seats => Rhoconnect.license.seats,
@@ -0,0 +1,15 @@
1
+ Server.api4 :login, :post, "/rc/#{Rhoconnect::API_VERSION}/system/login", true, {:verb => :post, :url => ['/login', '/api/admin/login']} do |params,user,server|
2
+ token = ''
3
+ server.logout
4
+ server.do_login
5
+ u = User.load(params[:login])
6
+ token = do_get_api_token(params, u)
7
+ end
8
+
9
+ def do_get_api_token(params, user)
10
+ if user and user.admin == 1 and user.token
11
+ user.token.value
12
+ else
13
+ raise ApiException.new(422, "Invalid/missing API user")
14
+ end
15
+ end
@@ -1,10 +1,11 @@
1
- Server.api :reset, :admin do |params,user|
1
+ Server.api4 :reset, :post, "/rc/#{Rhoconnect::API_VERSION}/system/reset", true, {:verb => :post, :url => ['/api/reset', '/api/admin/reset']} do |params,user|
2
+ keep_token = user.token.value
2
3
  Store.db.flushdb
3
4
  app_klass = Object.const_get(camelize(APP_NAME))
4
5
  if app_klass.singleton_methods.map(&:to_sym).include?(:initializer)
5
6
  app_klass.send :initializer, Rhoconnect.base_directory
6
7
  end
7
8
  # restoring previous token value after flushdb
8
- user.token = params[:api_token]
9
+ user.token = keep_token
9
10
  "DB reset"
10
11
  end
@@ -0,0 +1,4 @@
1
+ Server.api4 :save_adapter, :post, "/rc/#{Rhoconnect::API_VERSION}/system/appserver", \
2
+ true, {:verb => :post, :url => ['/api/save_adapter', '/api/source/save_adapter']} do |params,user|
3
+ Rhoconnect.appserver = params[:attributes]['adapter_url'] || params['adapter_url']
4
+ end
@@ -1,4 +1,5 @@
1
- Server.api :stats, :admin do |params,user|
1
+ Server.api4 :stats, :get, "/rc/#{Rhoconnect::API_VERSION}/system/stats", \
2
+ true, {:verb => :post, :url => ['/api/stats', '/api/admin/stats']} do |params,user|
2
3
  if Rhoconnect.stats == true
3
4
  names = params[:names]
4
5
  if names
@@ -1,7 +1,7 @@
1
- Server.api :create_user, :user do |params,user|
1
+ Server.api4 :create_user, :post, "/rc/#{Rhoconnect::API_VERSION}/users", true, {:verb => :post, :url => ['/api/create_user', '/api/user/create_user']} do |params,user|
2
2
  app = App.load(APP_NAME)
3
3
  u = User.create({:login => params[:attributes]['login']})
4
4
  u.password = params[:attributes]['password']
5
5
  app.users << u.login
6
6
  "User created"
7
- end
7
+ end
@@ -0,0 +1,6 @@
1
+ Server.api4 :delete_client, :delete, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id/clients/:client_id", \
2
+ true, {:verb => :post, :url => ['/api/delete_client', '/api/client/delete_client']} do |params,user|
3
+ Client.load(params[:client_id],{:source_name => '*'}).delete
4
+ User.load(params[:user_id]).clients.delete(params[:client_id])
5
+ "Client deleted"
6
+ end
@@ -1,4 +1,5 @@
1
- Server.api :delete_user, :user do |params,user|
1
+ Server.api4 :delete_user, :delete, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id", \
2
+ true, {:verb => :post, :url => ['/api/delete_user', '/api/user/delete_user']} do |params,user|
2
3
  User.load(params[:user_id]).delete
3
4
  App.load(APP_NAME).users.delete(params[:user_id])
4
5
  params = {:app_id => APP_NAME,:user_id => params[:user_id]}
@@ -0,0 +1,4 @@
1
+ Server.api4 :list_clients, :get, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id/clients", \
2
+ true, {:verb => :post, :url => ['/api/list_clients', '/api/client/list_clients']} do |params,user|
3
+ User.load(params[:user_id]).clients.members.to_json
4
+ end
@@ -0,0 +1,11 @@
1
+ Server.api4 :list_source_docs, :get, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id/sources/:source_id/docnames", \
2
+ true, {:verb => :post, :url => ['/api/list_source_docs', '/api/source/list_source_docs']} do |params,user|
3
+ res = {}
4
+ s = Source.load(params[:source_id], {:app_id => APP_NAME,:user_id => params[:user_id]})
5
+ [:md,:md_size,:md_copy,:errors].each do |doc|
6
+ db_key = s.docname(doc)
7
+ res.merge!(doc => db_key)
8
+ end
9
+ res.to_json
10
+ end
11
+
@@ -1,3 +1,3 @@
1
- Server.api :list_users, :user do |params,user|
1
+ Server.api4 :list_users, :get, "/rc/#{Rhoconnect::API_VERSION}/users", true, {:verb => :post, :url => ['/api/list_users', '/api/user/list_users']} do |params,user|
2
2
  App.load(APP_NAME).users.members.to_json
3
3
  end
@@ -0,0 +1,7 @@
1
+ Server.api4 :ping, :post, "/rc/#{Rhoconnect::API_VERSION}/users/ping", true, {:verb => :post, :url => ['/api/ping', '/api/client/ping']} do |params,user|
2
+ if params['async']
3
+ PingJob.enqueue(params)
4
+ else
5
+ PingJob.perform(params)
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ Server.api4 :show_user, :get, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id", true, nil do |params,user|
2
+ User.load(params[:user_id]).to_array.to_json
3
+ end
@@ -1,4 +1,5 @@
1
- Server.api :update_user, :user do |params,user|
2
- user.update(params[:attributes])
1
+ Server.api4 :update_user, :put, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id", \
2
+ true, {:verb => :post, :url => ["/api/update_user", '/api/user/update_user']} do |params,user|
3
+ User.load(params[:user_id]).update(params[:attributes])
3
4
  "User updated"
4
5
  end
@@ -0,0 +1,5 @@
1
+ Server.api4 :user_get_db_doc, :get, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id/sources/:source_id/docs/:doc", true, nil do |params,user|
2
+ s = Source.load(params[:source_id], {:app_id => APP_NAME,:user_id => params[:user_id]})
3
+ db_key = s.docname(params[:doc])
4
+ Store.get_db_doc(db_key)
5
+ end
@@ -0,0 +1,10 @@
1
+ Server.api4 :user_set_db_doc, :post, "/rc/#{Rhoconnect::API_VERSION}/users/:user_id/sources/:source_id/docs/:doc", true, nil do |params,user|
2
+ throw :halt, [500, "Unknown user '#{params[:user_id]}'"] unless User.is_exist?(params[:user_id])
3
+
4
+ s = Source.load(params[:source_id], {:app_id => APP_NAME,:user_id => params[:user_id]})
5
+ db_key = s.docname(params[:doc])
6
+ append_to_doc = params[:append]
7
+ append_to_doc ||= false
8
+ Store.set_db_doc(db_key,params[:data],append_to_doc)
9
+ ''
10
+ end
@@ -15,10 +15,14 @@ module Rhoconnect
15
15
  end
16
16
 
17
17
  def can_authenticate?
18
- # TODO: optimize it!
19
18
  self.delegate && self.delegate.singleton_methods.map(&:to_sym).include?(:authenticate)
20
19
  end
21
20
 
21
+ def can_ans_authenticate?
22
+ self.delegate && self.delegate.singleton_methods.map(&:to_sym).include?(:ans_authenticate)
23
+ end
24
+
25
+
22
26
  def authenticate(login, password, session)
23
27
  if Rhoconnect.appserver
24
28
  auth_result = DynamicAdapter.authenticate(login,password)
@@ -36,6 +40,10 @@ module Rhoconnect
36
40
  return user
37
41
  end
38
42
  end
43
+
44
+ def ans_authenticate(login, password)
45
+ self.delegate ? self.delegate.ans_authenticate(login, password) : false
46
+ end
39
47
 
40
48
  def delegate
41
49
  @delegate.nil? ? Object.const_get(camelize(self.name)) : @delegate
@@ -67,7 +75,9 @@ module Rhoconnect
67
75
  end
68
76
 
69
77
  def sources
70
- @@sources.uniq! || @@sources
78
+ @@sources.uniq!
79
+ # Sort sources array by priority
80
+ @@sources = @@sources.sort_by { |s| Source.load(s, {:app_id => self.name, :user_id => '*'}).priority }
71
81
  end
72
82
  end
73
83
  end
@@ -51,17 +51,13 @@ module Rhoconnect
51
51
  def execute_api_call(client_call = false)
52
52
  f = Fiber.current
53
53
  operation = proc {
54
- if client_call or check_api_token
55
- catch_all do
56
- res = yield params, (client_call ? current_user : api_user), self
57
- if params.has_key? :warning
58
- Rhoconnect.log params[:warning]
59
- response.headers['Warning'] = params[:warning]
60
- end
61
- res
54
+ catch_all do
55
+ res = yield params, current_user, self
56
+ if params.has_key? :warning
57
+ Rhoconnect.log params[:warning]
58
+ response.headers['Warning'] = params[:warning]
62
59
  end
63
- else
64
- [422, "No API token provided"]
60
+ res
65
61
  end
66
62
  }
67
63
  result = nil
@@ -9,7 +9,7 @@ module Rhoconnect
9
9
  field :user_id, :string
10
10
  field :refresh_time, :integer
11
11
  field :dbfile,:string
12
- set :sources, :string
12
+ list :sources, :string
13
13
  validates_presence_of :app_id, :user_id, :sources
14
14
 
15
15
  def completed?
@@ -20,7 +20,7 @@ module Rhoconnect
20
20
  end
21
21
 
22
22
  def delete
23
- sources.members.each do |source|
23
+ sources[0, -1].each do |source|
24
24
  s = Source.load(source,{:app_id => app_id, :user_id => user_id})
25
25
  Store.flash_data(s.docname(:md_copy)) if s
26
26
  end
@@ -28,7 +28,7 @@ module Rhoconnect
28
28
  end
29
29
 
30
30
  def process_sources
31
- sources.members.each do |source|
31
+ sources[0, -1].each do |source|
32
32
  s = Source.load(source,{:app_id => app_id, :user_id => user_id})
33
33
  if s
34
34
  SourceSync.new(s).process_query(nil)
@@ -58,7 +58,7 @@ module Rhoconnect
58
58
  def delete_files
59
59
  FileUtils.rm Dir.glob(File.join(Rhoconnect.base_directory, "#{self.url}*"))
60
60
  end
61
-
61
+
62
62
  class << self
63
63
  def create(fields={})
64
64
  fields[:id] = fields[:name]
@@ -2,13 +2,14 @@ module Rhoconnect
2
2
  class InvalidSourceNameError < RuntimeError; end
3
3
 
4
4
  class Client < Model
5
- field :device_type, :string
6
- field :device_pin, :string
7
- field :device_port, :string
8
- field :phone_id, :string
9
- field :user_id, :string
10
- field :last_sync, :datetime
11
- field :app_id, :string
5
+ field :device_type, :string
6
+ field :device_push_type, :string
7
+ field :device_pin, :string
8
+ field :device_port, :string
9
+ field :phone_id, :string
10
+ field :user_id, :string
11
+ field :last_sync, :datetime
12
+ field :app_id, :string
12
13
  attr_accessor :source_name
13
14
  validates_presence_of :app_id, :user_id
14
15
 
@@ -81,9 +82,9 @@ module Rhoconnect
81
82
  end
82
83
 
83
84
  def update_fields(params)
84
- [:device_type,:device_pin,:device_port,:phone_id].each do |setting|
85
+ [:device_type, :device_push_type,:device_pin,:device_port,:phone_id].each do |setting|
85
86
  self.send "#{setting}=".to_sym, params[setting].to_s if params[setting]
86
- end
87
+ end
87
88
  end
88
89
 
89
90
  private
@@ -2,10 +2,11 @@ module Rhoconnect
2
2
  class ClientSync
3
3
  attr_accessor :source,:client,:p_size,:source_sync
4
4
 
5
- VERSION = 3
6
5
  UNKNOWN_CLIENT = "Unknown client"
7
6
  UNKNOWN_SOURCE = "Unknown source"
8
7
 
8
+ # TODO : Remove in Rhoconnect 4.0
9
+ SYNC_VERSION = 3
9
10
 
10
11
  def initialize(source,client,p_size=nil)
11
12
  raise ArgumentError.new(UNKNOWN_CLIENT) unless client
@@ -73,7 +74,7 @@ module Rhoconnect
73
74
  else
74
75
  compute_errors_page
75
76
  res = build_page do |r|
76
- progress_count,total_count,r['insert'] = compute_page
77
+ total_count,r['insert'] = compute_page
77
78
  r['delete'] = compute_deleted_page
78
79
  r['links'] = compute_links_page
79
80
  r['metadata'] = compute_metadata
@@ -82,9 +83,13 @@ module Rhoconnect
82
83
  token = compute_token(@client.docname(:page_token))
83
84
  else
84
85
  _delete_errors_page
85
- end
86
+ end
86
87
  @client.put_data(:cd,res['insert'],true)
87
88
  @client.delete_data(:cd,res['delete'])
89
+ # TODO: progress count can not be computed properly
90
+ # without comparing what has actually changes
91
+ # so we need to obsolete it in the future versions
92
+ progress_count = 0
88
93
  end
89
94
  [token,progress_count,total_count,res]
90
95
  end
@@ -120,7 +125,7 @@ module Rhoconnect
120
125
  r['delete'] = @client.get_data(:delete_page)
121
126
  r['links'] = @client.get_data(:create_links_page)
122
127
  r['metadata'] = @client.get_value(:metadata_page)
123
- progress_count = @client.get_value(:cd_size).to_i
128
+ progress_count = 0
124
129
  total_count = @client.get_value(:total_count_page).to_i
125
130
  end
126
131
  end
@@ -162,27 +167,29 @@ module Rhoconnect
162
167
  # Computes diffs between master doc and client doc, trims it to page size,
163
168
  # stores page, and returns page as hash
164
169
  def compute_page
165
- res,diffsize,total_count = @source.lock(:md) do |s|
166
- res,diffsize = Store.get_diff_data(@client.docname(:cd),s.docname(:md),@p_size)
170
+ res,total_count = @source.lock(:md) do |s|
171
+ res = Store.get_diff_data(@client.docname(:cd),s.docname(:md),@p_size)
167
172
  total_count = s.get_value(:md_size).to_i
168
- [res,diffsize,total_count]
173
+ [res,total_count]
169
174
  end
175
+ # until sync is not done - set cd_size to 0
176
+ # once there are no changes, then, set cd_size to md_size
177
+ cd_size = res.size > 0 ? 0 : total_count
178
+ @client.put_value(:cd_size, cd_size)
170
179
  @client.put_data(:page,res)
171
- progress_count = total_count - diffsize
172
- @client.put_value(:cd_size,progress_count)
173
180
  @client.put_value(:total_count_page,total_count)
174
- [progress_count,total_count,res]
181
+ [total_count,res]
175
182
  end
176
183
 
177
184
  # Computes search result, updates md for source and cd for client with the result
178
185
  def compute_search
179
- client_res,diffsize = Store.get_diff_data(@client.docname(:cd),@client.docname(:search),@p_size)
186
+ client_res = Store.get_diff_data(@client.docname(:cd),@client.docname(:search),@p_size)
180
187
  @client.put_data(:cd,client_res,true)
181
188
  @client.update_count(:cd_size,client_res.size)
182
189
  @client.put_data(:search_page,client_res)
183
190
 
184
191
  @source.lock(:md) do |s|
185
- source_diff,source_diffsize = Store.get_diff_data(s.docname(:md),@client.docname(:cd))
192
+ source_diff = Store.get_diff_data(s.docname(:md),@client.docname(:cd))
186
193
  s.put_data(:md,source_diff,true)
187
194
  s.update_count(:md_size,source_diff.size)
188
195
  end
@@ -196,12 +203,10 @@ module Rhoconnect
196
203
  res = {}
197
204
  delete_page_doc = @client.docname(:delete_page)
198
205
  page_size = @p_size
199
- diff = @source.lock(:md) { |s| Store.get_diff_data(s.docname(:md),@client.docname(:cd))[0] }
206
+ diff = @source.lock(:md) { |s| Store.get_diff_data(s.docname(:md),@client.docname(:cd),@p_size) }
200
207
  diff.each do |key,value|
201
208
  res[key] = value
202
- value.each do |attrib,val|
203
- Store.db.sadd(delete_page_doc,setelement(key,attrib,val))
204
- end
209
+ Store.put_object(delete_page_doc,key,value)
205
210
  page_size -= 1
206
211
  break if page_size <= 0
207
212
  end
@@ -347,14 +352,14 @@ module Rhoconnect
347
352
  def _format_search_result(res={},diffsize=nil)
348
353
  error = @client.get_data(:search_errors)
349
354
  if not error.empty?
350
- [ {'version'=>VERSION},
355
+ [ {'version'=>SYNC_VERSION},
351
356
  {'source'=>@source.name},
352
357
  {'search-error'=>error} ]
353
358
  else
354
359
  search_token = @client.get_value(:search_token)
355
360
  search_token ||= ''
356
361
  return [] if res.empty?
357
- [ {'version'=>VERSION},
362
+ [ {'version'=>SYNC_VERSION},
358
363
  {'token' => search_token},
359
364
  {'source'=>@source.name},
360
365
  {'count'=>res.size},
@@ -423,7 +428,7 @@ module Rhoconnect
423
428
  count = 0
424
429
  count += res['insert'].length if res['insert']
425
430
  count += res['delete'].length if res['delete']
426
- [ {'version'=>VERSION},
431
+ [ {'version'=>SYNC_VERSION},
427
432
  {'token'=>(token ? token : '')},
428
433
  {'count'=>count},
429
434
  {'progress_count'=>progress_count},
@@ -2,17 +2,33 @@ module Document
2
2
 
3
3
  # Store wrapper methods for document
4
4
  def get_data(doctype,type=Hash)
5
- Store.get_data(docname(doctype),type)
5
+ Store.get_data(docname(doctype), type)
6
+ end
7
+
8
+ def get_object(doctype, key)
9
+ Store.get_object(docname(doctype), key)
10
+ end
11
+
12
+ def get_list(doctype)
13
+ Store.get_list(docname(doctype))
6
14
  end
7
15
 
8
16
  def get_value(doctype)
9
17
  Store.get_value(docname(doctype))
10
18
  end
11
19
 
20
+ def put_object(doctype, key, data={})
21
+ Store.put_object(docname(doctype), key, data)
22
+ end
23
+
12
24
  def put_data(doctype,data,append=false)
13
25
  Store.put_data(docname(doctype),data,append)
14
26
  end
15
27
 
28
+ def put_list(doctype,data,append=false)
29
+ Store.put_list(docname(doctype),data,append)
30
+ end
31
+
16
32
  def update_objects(doctype,updates)
17
33
  Store.update_objects(docname(doctype),updates)
18
34
  end
@@ -62,8 +78,6 @@ module Document
62
78
 
63
79
  # Update count for a given document
64
80
  def update_count(doctype,count)
65
- name = docname(doctype)
66
- value = Store.db.get(name).to_i + count
67
- Store.db.set(name,value < 0 ? 0 : value)
81
+ Store.update_count(docname(doctype), count)
68
82
  end
69
83
  end
@@ -205,8 +205,10 @@ module GraphHelper
205
205
  end
206
206
 
207
207
  def get_sources(partition_type)
208
- sources = App.load(APP_NAME).sources
209
- puts "sources is -- #{sources}"
208
+ # app.sources returns reference
209
+ # so we need to make a copy
210
+ # otherwise we will end up modifying the @@sources variable in App
211
+ sources = App.load(APP_NAME).sources.clone
210
212
  if partition_type.nil? or partition_type == 'all'
211
213
  sources
212
214
  else