rhoconnect 3.4.5 → 4.0.0.beta.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (337) hide show
  1. data/CHANGELOG.md +57 -3
  2. data/Gemfile +9 -7
  3. data/Gemfile.lock +37 -37
  4. data/Rakefile +18 -7
  5. data/bench/benchapp/Gemfile +1 -1
  6. data/bench/benchapp/config.ru +0 -3
  7. data/bench/benchapp/controllers/ruby/application.rb +17 -0
  8. data/bench/benchapp/controllers/ruby/application_controller.rb +17 -0
  9. data/bench/benchapp/controllers/ruby/mock_adapter_controller.rb +8 -0
  10. data/bench/benchapp/controllers/ruby/queue_mock_adapter_controller.rb +8 -0
  11. data/bench/benchapp/{sources → models/ruby}/mock_adapter.rb +1 -1
  12. data/bench/benchapp/{sources → models/ruby}/queue_mock_adapter.rb +0 -0
  13. data/bench/benchapp/spec/{sources → models/ruby}/mock_adapter_spec.rb +1 -1
  14. data/bench/benchapp/spec/{sources → models/ruby}/queue_mock_adapter_spec.rb +1 -1
  15. data/bench/benchapp/spec/spec_helper.rb +2 -2
  16. data/bench/blobapp/Gemfile +1 -1
  17. data/bench/blobapp/config.ru +0 -3
  18. data/bench/blobapp/controllers/ruby/application_controller.rb +17 -0
  19. data/bench/blobapp/controllers/ruby/blob_adapter_controller.rb +8 -0
  20. data/bench/blobapp/{sources → models/ruby}/blob_adapter.rb +9 -2
  21. data/bench/blobapp/spec/{sources → models/ruby}/blob_adapter_spec.rb +1 -1
  22. data/bench/blobapp/spec/spec_helper.rb +1 -1
  23. data/bench/lib/bench/cli.rb +1 -1
  24. data/bench/scripts/blob_cud_script.rb +1 -1
  25. data/bench/scripts/query_md_script.rb +1 -1
  26. data/bench/scripts/query_only_script.rb +1 -1
  27. data/bench/scripts/query_script.rb +1 -1
  28. data/bench/scripts/test_query_script.rb +7 -1
  29. data/bench/spec/mock_adapter_spec.rb +1 -1
  30. data/bench/spec/result_spec.rb +3 -3
  31. data/bin/rhoconnect +5 -3
  32. data/commands/dtach/dtach_install.rb +2 -2
  33. data/commands/execute.rb +8 -3
  34. data/commands/generators/app.rb +3 -3
  35. data/commands/generators/controller.rb +6 -0
  36. data/commands/generators/model.rb +6 -0
  37. data/commands/generators/source.rb +3 -3
  38. data/commands/generators/update.rb +1 -1
  39. data/commands/redis/redis_about.rb +2 -2
  40. data/commands/redis/redis_download.rb +1 -1
  41. data/commands/redis/redis_install.rb +4 -3
  42. data/commands/redis/redis_restart.rb +4 -4
  43. data/commands/redis/redis_start.rb +5 -4
  44. data/commands/redis/redis_startbg.rb +5 -4
  45. data/commands/redis/redis_status.rb +13 -0
  46. data/commands/redis/redis_stop.rb +3 -3
  47. data/commands/rhoconnect/config.rb +28 -16
  48. data/commands/rhoconnect/flushdb.rb +1 -2
  49. data/commands/rhoconnect/get_token.rb +15 -11
  50. data/commands/rhoconnect/restart.rb +13 -5
  51. data/commands/rhoconnect/set_admin_password.rb +8 -8
  52. data/commands/rhoconnect/start.rb +74 -16
  53. data/commands/rhoconnect/startbg.rb +1 -1
  54. data/commands/rhoconnect/startdebug.rb +1 -1
  55. data/commands/rhoconnect/stop.rb +13 -1
  56. data/commands/rhoconnect/web.rb +5 -5
  57. data/commands/rhoconnect_console/console.rb +7 -5
  58. data/commands/{rhoconnect → rhoconnect_spec}/spec.rb +0 -0
  59. data/commands/rhoconnect_war/war.rb +9 -9
  60. data/commands/utilities/blank_app.ru +56 -0
  61. data/commands/utilities/redis_runner.rb +54 -19
  62. data/doc/authentication.txt +80 -6
  63. data/doc/blob-sync.txt +104 -97
  64. data/doc/bulk-sync.txt +1 -1
  65. data/doc/client-java.txt +3 -3
  66. data/doc/client-objc.txt +2 -2
  67. data/doc/client.txt +4 -4
  68. data/doc/command-line.txt +105 -200
  69. data/doc/data-partitioning.txt +40 -0
  70. data/doc/deploying.txt +249 -77
  71. data/doc/extending-rhoconnect-server.txt +40 -57
  72. data/doc/heroku-addon.txt +2 -0
  73. data/doc/install.txt +45 -95
  74. data/doc/introduction.txt +1 -1
  75. data/doc/java-plugin.txt +365 -190
  76. data/doc/metadata.txt +1 -1
  77. data/doc/migration.txt +108 -142
  78. data/doc/preparing-production.txt +1 -1
  79. data/doc/push-backend-setup.txt +2 -0
  80. data/doc/push-client-setup-android.txt +78 -0
  81. data/doc/push-client-setup-bb.txt +81 -0
  82. data/doc/push-client-setup-ios.txt +70 -0
  83. data/doc/push-client-setup-rps.txt +200 -0
  84. data/doc/push-client-setup.txt +63 -66
  85. data/doc/push-server-setup.txt +67 -40
  86. data/doc/push-testing.txt +29 -0
  87. data/doc/push.txt +21 -6
  88. data/doc/rest-api.txt +128 -55
  89. data/doc/rhoconnect-redis-stack.txt +120 -0
  90. data/doc/settings.txt +4 -12
  91. data/doc/source-adapters-intro.txt +28 -0
  92. data/doc/source-adapters.txt +235 -272
  93. data/doc/stats-middleware.txt +9 -29
  94. data/doc/supported-platforms.txt +21 -30
  95. data/doc/testing.txt +40 -42
  96. data/doc/tutorial.txt +72 -57
  97. data/examples/simple/Gemfile +1 -1
  98. data/examples/simple/application.rb +4 -5
  99. data/examples/simple/my_server.rb +2 -2
  100. data/examples/simple/settings/settings.yml +1 -1
  101. data/generators/rhoconnect.rb +151 -50
  102. data/generators/templates/application/Gemfile +1 -1
  103. data/generators/templates/application/Rakefile +3 -3
  104. data/generators/templates/application/config.ru +1 -4
  105. data/generators/templates/application/controllers/application_controller.rb +17 -0
  106. data/generators/templates/application/controllers/js/application_controller.js +14 -0
  107. data/generators/templates/application/controllers/ruby/application_controller.rb +17 -0
  108. data/generators/templates/application/package.json +8 -0
  109. data/generators/templates/application/rcgemfile +2 -5
  110. data/generators/templates/application/settings/settings.yml +3 -3
  111. data/generators/templates/application/spec/application_controller_spec.rb +23 -0
  112. data/generators/templates/application/spec/js_spec.rb +25 -0
  113. data/generators/templates/application/spec/spec_helper.rb +21 -7
  114. data/generators/templates/source/controllers/js/controller.js +7 -0
  115. data/generators/templates/source/controllers/ruby/controller.rb +8 -0
  116. data/generators/templates/source/controllers/ruby/controller_spec.rb +27 -0
  117. data/generators/templates/source/models/js/model.js +46 -0
  118. data/generators/templates/source/{source_adapter.rb → models/ruby/model.rb} +15 -10
  119. data/generators/templates/source/{source_spec.rb → models/ruby/model_spec.rb} +1 -1
  120. data/install.sh +5 -5
  121. data/installer/unix-like/create_texts.rb +2 -2
  122. data/installer/unix-like/rho_connect_install_constants.rb +2 -2
  123. data/installer/unix-like/rho_connect_install_utilities.rb +1 -1
  124. data/installer/utils/constants.rb +4 -4
  125. data/js-adapters/ballroom.js +216 -0
  126. data/js-adapters/node.rb +52 -0
  127. data/js-adapters/node_channel.rb +181 -0
  128. data/js-adapters/request.js +27 -0
  129. data/js-adapters/response.js +57 -0
  130. data/js-adapters/rhoconnect_helpers.js +60 -0
  131. data/js-adapters/router.js +60 -0
  132. data/js-adapters/server.js +5 -0
  133. data/lib/rhoconnect/api/app/ans_login.rb +3 -3
  134. data/lib/rhoconnect/api/app/bulk_data.rb +10 -10
  135. data/lib/rhoconnect/api/app/fast_delete.rb +11 -10
  136. data/lib/rhoconnect/api/app/fast_insert.rb +11 -10
  137. data/lib/rhoconnect/api/app/fast_update.rb +11 -10
  138. data/lib/rhoconnect/api/app/login.rb +5 -5
  139. data/lib/rhoconnect/api/app/push_deletes.rb +12 -11
  140. data/lib/rhoconnect/api/app/push_objects.rb +12 -11
  141. data/lib/rhoconnect/api/app/query.rb +8 -7
  142. data/lib/rhoconnect/api/app/queue_updates.rb +98 -94
  143. data/lib/rhoconnect/api/app/search.rb +8 -7
  144. data/lib/rhoconnect/api/client/client_get_db_doc.rb +5 -5
  145. data/lib/rhoconnect/api/client/client_set_db_doc.rb +8 -8
  146. data/lib/rhoconnect/api/client/create.rb +7 -7
  147. data/lib/rhoconnect/api/client/get_client_params.rb +4 -4
  148. data/lib/rhoconnect/api/client/list_client_docs.rb +17 -17
  149. data/lib/rhoconnect/api/client/register.rb +12 -12
  150. data/lib/rhoconnect/api/client/reset.rb +5 -5
  151. data/lib/rhoconnect/api/readstate/set_refresh_time.rb +9 -9
  152. data/lib/rhoconnect/api/source/get_source_params.rb +4 -4
  153. data/lib/rhoconnect/api/source/list_sources.rb +16 -16
  154. data/lib/rhoconnect/api/source/update_source_params.rb +6 -6
  155. data/lib/rhoconnect/api/store/get_db_doc.rb +4 -4
  156. data/lib/rhoconnect/api/store/set_db_doc.rb +7 -7
  157. data/lib/rhoconnect/api/system/get_adapter.rb +4 -4
  158. data/lib/rhoconnect/api/system/get_license_info.rb +8 -8
  159. data/lib/rhoconnect/api/system/login.rb +15 -15
  160. data/lib/rhoconnect/api/system/reset.rb +11 -11
  161. data/lib/rhoconnect/api/system/save_adapter.rb +4 -4
  162. data/lib/rhoconnect/api/system/stats.rb +22 -22
  163. data/lib/rhoconnect/api/user/create_user.rb +7 -7
  164. data/lib/rhoconnect/api/user/delete_client.rb +6 -6
  165. data/lib/rhoconnect/api/user/delete_user.rb +11 -10
  166. data/lib/rhoconnect/api/user/list_clients.rb +4 -4
  167. data/lib/rhoconnect/api/user/list_source_docs.rb +10 -10
  168. data/lib/rhoconnect/api/user/list_users.rb +3 -3
  169. data/lib/rhoconnect/api/user/ping.rb +3 -3
  170. data/lib/rhoconnect/api/user/show_user.rb +3 -3
  171. data/lib/rhoconnect/api/user/update_user.rb +5 -5
  172. data/lib/rhoconnect/api/user/user_get_db_doc.rb +5 -5
  173. data/lib/rhoconnect/api/user/user_set_db_doc.rb +10 -10
  174. data/lib/rhoconnect/api_token.rb +5 -6
  175. data/lib/rhoconnect/app.rb +6 -46
  176. data/lib/rhoconnect/application/init.rb +5 -2
  177. data/lib/rhoconnect/async.rb +76 -39
  178. data/lib/rhoconnect/bulk_data/bulk_data.rb +6 -4
  179. data/lib/rhoconnect/client.rb +59 -9
  180. data/lib/rhoconnect/condition/admin_required.rb +27 -0
  181. data/lib/rhoconnect/condition/client_required.rb +50 -0
  182. data/lib/rhoconnect/condition/login_required.rb +22 -0
  183. data/lib/rhoconnect/condition/source_required.rb +49 -0
  184. data/lib/rhoconnect/condition/verbs.rb +17 -0
  185. data/lib/rhoconnect/condition/verify_success.rb +19 -0
  186. data/lib/rhoconnect/controller/app_base.rb +74 -0
  187. data/lib/rhoconnect/controller/base.rb +68 -0
  188. data/lib/rhoconnect/controller/clients_controller.rb +79 -0
  189. data/lib/rhoconnect/controller/dynamic_adapter_controller.rb +93 -0
  190. data/lib/rhoconnect/controller/js_base.rb +124 -0
  191. data/lib/rhoconnect/controller/read_state_controller.rb +22 -0
  192. data/lib/rhoconnect/controller/source_adapter_base.rb +14 -0
  193. data/lib/rhoconnect/controller/sources_controller.rb +44 -0
  194. data/lib/rhoconnect/controller/store_controller.rb +25 -0
  195. data/lib/rhoconnect/controller/system_controller.rb +67 -0
  196. data/lib/rhoconnect/controller/users_controller.rb +99 -0
  197. data/lib/rhoconnect/db_adapter.rb +1 -3
  198. data/lib/rhoconnect/document.rb +159 -50
  199. data/lib/rhoconnect/handler/authenticate/execute_methods.rb +77 -0
  200. data/lib/rhoconnect/handler/authenticate/runner.rb +49 -0
  201. data/lib/rhoconnect/handler/authenticate.rb +3 -0
  202. data/lib/rhoconnect/handler/bulk_data.rb +28 -0
  203. data/lib/rhoconnect/handler/changes/engine.rb +271 -0
  204. data/lib/rhoconnect/handler/changes/execute_methods.rb +88 -0
  205. data/lib/rhoconnect/handler/changes/pass_through_runner.rb +11 -0
  206. data/lib/rhoconnect/handler/changes/runner.rb +53 -0
  207. data/lib/rhoconnect/handler/changes.rb +31 -0
  208. data/lib/rhoconnect/handler/helpers/auth_method.rb +29 -0
  209. data/lib/rhoconnect/handler/helpers/binding.rb +18 -0
  210. data/lib/rhoconnect/handler/helpers/bulk_data.rb +53 -0
  211. data/lib/rhoconnect/handler/helpers/source_job.rb +14 -0
  212. data/lib/rhoconnect/handler/helpers.rb +4 -0
  213. data/lib/rhoconnect/handler/plugin_callbacks/execute_methods.rb +99 -0
  214. data/lib/rhoconnect/handler/plugin_callbacks/runner.rb +28 -0
  215. data/lib/rhoconnect/handler/plugin_callbacks.rb +67 -0
  216. data/lib/rhoconnect/handler/query/engine.rb +93 -0
  217. data/lib/rhoconnect/handler/query/execute_methods.rb +21 -0
  218. data/lib/rhoconnect/handler/query/pass_through_runner.rb +35 -0
  219. data/lib/rhoconnect/handler/query/runner.rb +270 -0
  220. data/lib/rhoconnect/handler/query.rb +19 -0
  221. data/lib/rhoconnect/handler/search/engine.rb +60 -0
  222. data/lib/rhoconnect/handler/search/execute_methods.rb +32 -0
  223. data/lib/rhoconnect/handler/search/pass_through_runner.rb +18 -0
  224. data/lib/rhoconnect/handler/search/runner.rb +104 -0
  225. data/lib/rhoconnect/handler/search.rb +26 -0
  226. data/lib/rhoconnect/handler/sync.rb +29 -0
  227. data/lib/rhoconnect/jobs/source_job.rb +13 -4
  228. data/lib/rhoconnect/js_adapter.rb +79 -0
  229. data/lib/rhoconnect/license.rb +10 -2
  230. data/lib/rhoconnect/middleware/current_user.rb +14 -1
  231. data/lib/rhoconnect/middleware/helpers.rb +10 -93
  232. data/lib/rhoconnect/middleware/x_domain_session_wrapper.rb +1 -1
  233. data/lib/rhoconnect/model/base.rb +229 -0
  234. data/lib/rhoconnect/model/dynamic_adapter_model.rb +90 -0
  235. data/lib/rhoconnect/model/js_base.rb +121 -0
  236. data/lib/rhoconnect/ping/android.rb +1 -1
  237. data/lib/rhoconnect/predefined_adapters/bench_adapter.rb +7 -4
  238. data/lib/rhoconnect/read_state.rb +3 -3
  239. data/lib/rhoconnect/server.rb +159 -190
  240. data/lib/rhoconnect/source.rb +100 -11
  241. data/lib/rhoconnect/stats/record.rb +10 -10
  242. data/lib/rhoconnect/store.rb +905 -591
  243. data/lib/rhoconnect/{model.rb → store_orm.rb} +53 -115
  244. data/lib/rhoconnect/tasks.rb +18 -4
  245. data/lib/rhoconnect/test_methods.rb +30 -17
  246. data/lib/rhoconnect/user.rb +35 -17
  247. data/lib/rhoconnect/utilities.rb +1 -1
  248. data/lib/rhoconnect/version.rb +2 -2
  249. data/lib/rhoconnect/web-console/server.rb +29 -14
  250. data/lib/rhoconnect/web-console/views/home.js +10 -10
  251. data/lib/rhoconnect/web-console/views/new_ping.js +1 -1
  252. data/lib/rhoconnect.rb +120 -51
  253. data/rhoconnect.gemspec +4 -3
  254. data/spec/api/api_helper.rb +1 -6
  255. data/spec/api/app/fast_delete_spec.rb +4 -4
  256. data/spec/api/app/fast_insert_spec.rb +4 -4
  257. data/spec/api/app/fast_update_spec.rb +8 -8
  258. data/spec/api/app/push_deletes_spec.rb +2 -2
  259. data/spec/api/app/push_objects_spec.rb +5 -5
  260. data/spec/api/client/client_get_db_doc_spec.rb +6 -4
  261. data/spec/api/client/client_set_db_doc_spec.rb +3 -2
  262. data/spec/api/client/get_client_params_spec.rb +14 -0
  263. data/spec/api/client/list_client_docs_spec.rb +30 -20
  264. data/spec/api/client/reset_spec.rb +36 -0
  265. data/spec/api/source/get_source_params_spec.rb +23 -17
  266. data/spec/api/system/get_license_info_spec.rb +0 -20
  267. data/spec/api/system/login_spec.rb +8 -0
  268. data/spec/api/system/reset_spec.rb +0 -1
  269. data/spec/api/system/stats_spec.rb +5 -5
  270. data/spec/api/user/create_user_spec.rb +14 -6
  271. data/spec/api/user/delete_user_spec.rb +20 -18
  272. data/spec/api/user/list_users_spec.rb +5 -6
  273. data/spec/api/user/update_user_spec.rb +5 -4
  274. data/spec/apps/rhotestapp/config.ru +16 -1
  275. data/spec/apps/rhotestapp/controllers/js/js_sample_controller.js +23 -0
  276. data/spec/apps/rhotestapp/controllers/js/sample2_controller.js +32 -0
  277. data/spec/apps/rhotestapp/controllers/ruby/application_controller.rb +21 -0
  278. data/spec/apps/rhotestapp/controllers/ruby/sample_adapter_controller.rb +8 -0
  279. data/spec/apps/rhotestapp/models/js/js_sample.js +55 -0
  280. data/spec/apps/rhotestapp/models/js/sample2.js +25 -0
  281. data/spec/apps/rhotestapp/{sources → models/ruby}/base_adapter.rb +0 -0
  282. data/spec/apps/rhotestapp/{sources → models/ruby}/fixed_schema_adapter.rb +0 -0
  283. data/spec/apps/rhotestapp/{sources → models/ruby}/other_adapter.rb +0 -0
  284. data/spec/apps/rhotestapp/{sources → models/ruby}/sample_adapter.rb +0 -0
  285. data/spec/apps/rhotestapp/{sources → models/ruby}/simple_adapter.rb +2 -2
  286. data/spec/apps/rhotestapp/{sources → models/ruby}/sub_adapter.rb +0 -0
  287. data/spec/apps/rhotestapp/settings/settings.yml +0 -1
  288. data/spec/bulk_data/bulk_data_spec.rb +20 -5
  289. data/spec/cli/cli_spec.rb +83 -0
  290. data/spec/client_spec.rb +20 -17
  291. data/spec/client_sync_spec.rb +244 -406
  292. data/spec/controllers/js_base_spec.rb +89 -0
  293. data/spec/doc/doc_spec.rb +18 -18
  294. data/spec/document_spec.rb +29 -13
  295. data/spec/dynamic_adapter_spec.rb +6 -6
  296. data/spec/generator/generator_spec.rb +7 -4
  297. data/spec/jobs/bulk_data_job_spec.rb +14 -10
  298. data/spec/jobs/source_job_spec.rb +8 -8
  299. data/spec/license_spec.rb +5 -2
  300. data/spec/models/js_model_spec.rb +39 -0
  301. data/spec/node_spec.rb +42 -0
  302. data/spec/perf/store_perf_spec.rb +67 -12
  303. data/spec/ping/android_spec.rb +1 -1
  304. data/spec/read_state_spec.rb +1 -1
  305. data/spec/rhoconnect_spec.rb +1 -1
  306. data/spec/server/cors_spec.rb +14 -18
  307. data/spec/server/server_spec.rb +265 -88
  308. data/spec/server/stats_spec.rb +1 -1
  309. data/spec/source_adapter_spec.rb +54 -27
  310. data/spec/source_spec.rb +8 -3
  311. data/spec/source_sync_spec.rb +538 -468
  312. data/spec/spec_helper.rb +35 -4
  313. data/spec/stats/record_spec.rb +10 -10
  314. data/spec/{model_spec.rb → store_orm_spec.rb} +56 -54
  315. data/spec/store_spec.rb +159 -179
  316. data/spec/support/shared_examples.rb +36 -27
  317. data/spec/sync_states_spec.rb +40 -33
  318. data/spec/test_methods_spec.rb +18 -14
  319. data/spec/user_spec.rb +17 -30
  320. metadata +156 -52
  321. data/bench/benchapp/application.rb +0 -39
  322. data/bench/blobapp/application.rb +0 -44
  323. data/commands/rhoconnect/clean_start.rb +0 -9
  324. data/commands/rhoconnect/create_user.rb +0 -18
  325. data/commands/rhoconnect/delete_device.rb +0 -9
  326. data/commands/rhoconnect/delete_user.rb +0 -8
  327. data/commands/rhoconnect/reset.rb +0 -16
  328. data/commands/rhoconnect/reset_refresh.rb +0 -11
  329. data/generators/templates/application/application.rb +0 -43
  330. data/lib/rhoconnect/client_sync.rb +0 -434
  331. data/lib/rhoconnect/dynamic_adapter.rb +0 -91
  332. data/lib/rhoconnect/middleware/admin_user.rb +0 -23
  333. data/lib/rhoconnect/middleware/current_request.rb +0 -16
  334. data/lib/rhoconnect/middleware/login_required.rb +0 -22
  335. data/lib/rhoconnect/source_adapter.rb +0 -132
  336. data/lib/rhoconnect/source_sync.rb +0 -464
  337. data/spec/apps/rhotestapp/application.rb +0 -23
data/doc/java-plugin.txt CHANGED
@@ -1,88 +1,40 @@
1
1
  RhoConnect-Java
2
2
  ===
3
3
 
4
- The RhoConnect-Java library is designed for the [RhoConnect](http://rhomobile.com/products/rhoconnect/) Application Integration Server.
4
+ RhoConnect-Java library is designed for the [RhoConnect](http://rhomobile.com/products/rhoconnect/) Application Integration Server.
5
5
 
6
- Using the RhoConnect-Java plugin jar file, your [Spring 3 MVC](http://www.springsource.org/) application's data will transparently synchronize with a mobile application built on the [Rhodes framework](http://rhomobile.com/products/rhodes), or any of the available [RhoConnect clients](http://rhomobile.com/products/rhoconnect/).
7
-
8
- <img src='https://s3.amazonaws.com/rhodocs/rhoconnect-service/rhoconnect-plugin-java.jpg' alt='image' />
6
+ Using the RhoConnect-Java plugin, your [Spring 3 MVC](http://www.springsource.org/) application's data will transparently synchronize with a mobile application built on the [Rhodes framework](http://rhomobile.com/products/rhodes), or any of the available [RhoConnect clients](http://rhomobile.com/products/rhoconnect/).
9
7
 
10
8
  ## Prerequisites
11
9
 
12
10
  * Java (1.6)
13
- * Maven2 (2.2.1)
11
+ * Maven
14
12
  * Git
15
- * [Rhoconnect-java](https://github.com/downloads/rhomobile/rhoconnect-java/rhoconnect-java-1.0.1.jar) plugin jar file
16
-
17
- ## Getting Started
18
-
19
- We assume that you have a complete java end-to-end application using Spring 3.0 MVC as the front end technology and Hibernate as the backend ORM. For this application, we will also use Maven2 for build and dependency management and a database to persist the data. The database is accessed by a Data Access (DAO) layer.
20
-
21
- ## A Sample Java Spring 3.0 MVC Backend Application
22
-
23
- The instructions in the following steps show how to install the `rhoconnect-java` plugin jar file into an existing Java end-to-end application using Sprint 3.0 MVC as the front end technology, and Hibernate as the backend ORM. For an example, you can download and install the [RhoconnectJavaSample](https://github.com/shurab/RhoconnectJavaSample) application.
24
-
25
- This sample Java application was created using Sprint 3.0 MVC, using [this tutorial to Create Spring 3 MVC Hibernate 3 Example using Maven in Eclipse](http://viralpatel.net/blogs/2010/11/spring3-mvc-hibernate-maven-tutorial-eclipse-example.html).
26
-
27
- To install this sample application, navigate in your web browser to [https://github.com/shurab/RhoconnectJavaSample](https://github.com/shurab/RhoconnectJavaSample) and download it as a zip file. Unzip it and rename the unzipped folder to RhoconnectJavaSample.
28
-
29
- Navigate into the `RhoconnectJavaSample` folder and run these commands to run the sample Java application.
30
-
31
- :::term
32
- $ mvn clean
33
- $ mvn jetty:run
34
-
35
- When you see `[INFO] Started Jetty Server`, open a web browser and navigate to `http://localhost:8080/contacts/index` to see this application running.
36
-
37
- <img src="http://rhodocs.s3.amazonaws.com/rhoconnect-plugin/java-backend-running.png">
13
+ * [rhoconnect-java](https://s3.amazonaws.com/rhoconnect-java/rhoconnect-java-1.0.2.jar) RhoConnect Java plugin jar
14
+ * [rhoconnect-java-api](https://s3.amazonaws.com/rhoconnect-java/rhoconnect-java-api-1.0.0.jar) RhoConnect Java API jar
38
15
 
39
- ## Settings for the Client App
16
+ ## Getting started
40
17
 
41
- Your client application needs to have its model match the model used in your Java Sprint 3.0 MVC backend application. For example, you can generate a Rhodes application for a Contact model to match the RhoconnectJavaSample application:
18
+ We assume that you have a complete java end-to-end application using Spring 3.0 MVC as the front end technology and Hibernate as backend ORM. For this application we will also use Maven for build and dependency management and some database to persist the data. The database is accessed by a Data Access (DAO) layer.
42
19
 
43
- :::term
44
- $ rhodes app contact-app
45
- $ cd contact-app
46
- $ rhodes model contact lastname,firstname,email,telephone
20
+ Copy [rhoconnect-java](https://s3.amazonaws.com/rhoconnect-java/rhoconnect-java-1.0.2.jar) and [rhoconnect-java-api](https://s3.amazonaws.com/rhoconnect-java/rhoconnect-java-api-1.0.0.jar) jar files to your PC.
21
+ You can also create target rhoconnect-java plugin jar from sources by cloning rhoconnect-java repository
47
22
 
23
+ :::term
24
+ $ git clone git@github.com:rhomobile/rhoconnect-java.git
48
25
 
49
- Edit the `rhoconfig.txt` configuration file to point to your RhoConnect server, where <your_rhoconnect_server_url> is the url for your RhoConnect server.
50
-
51
- :::term
52
- syncserver = 'http://<your_rhoconnect_server_url>/application'
53
-
54
- And edit the `app/index.erb` view file to say Contacts:
55
-
56
- :::html
57
- ...
58
- <li><a href="Contact">Contacts</a></li>
59
- ...
60
-
61
- And edit `app/Contact/contact.rb` file to enable sync.
62
-
63
- :::ruby
64
- ...
65
- enable :sync
66
- ...
67
-
68
- ## Settings for the RhoConnect Server App
69
-
70
- You must generate a RhoConnect server application and edit its settings for the RhoConnect Java plugin.
26
+ and executing in cloned project directory the following commands:
71
27
 
72
- :::term
73
- $ rhoconnect app syncserver
74
- $ cd syncserver; bundle install
28
+ :::term
29
+ $ mvn package
75
30
 
76
- Edit the `settings/settings.yml` development section to add an api\_token key/value pair. This value is the same as the api\_token that you will set in the `WEB-INF/spring-servlet.xml` file for your Java backend application.
31
+ The archived rhoconnect-java-x.y.z.jar file will be created in the project java-plugin/target/ directory. The accompanying rhoconnect-java-api-x.y.z.jar file will be created in the project java-api/target/ directory.
77
32
 
78
- :::term
79
- :development:
80
- ...
81
- :api_token: rhoconnect_api_token
33
+ For testing and evaluation purposes you can use [RhoconnectJavaSample](https://github.com/shurab/RhoconnectJavaSample) application as a starting point before continuing with the following steps.
82
34
 
83
- ## Adding Dependencies to Your Java Application Maven 2 POM
35
+ ### Adding Dependencies to Your Maven Project
84
36
 
85
- Add dependencies to the Apache Maven 2 project object model (POM) in your Java application by plugging the code below into the `pom.xml` file. This adds dependencies for log4j, Apache common beanutils, and Jackson JSON mapper.
37
+ Add dependencies to your Apache Maven project object model (POM): log4j, Apache common beanutils, and Jackson JSON mapper. In the RhoconnectJavaSample application, this code is in the pom.xml file.
86
38
 
87
39
  :::xml
88
40
  <!-- Log4j -->
@@ -107,18 +59,16 @@ Add dependencies to the Apache Maven 2 project object model (POM) in your Java a
107
59
  <optional>false</optional>
108
60
  </dependency>
109
61
 
110
- ## Adding the rhoconnect-java Plugin Jar File to Your Java Backend Application
111
-
112
- At this time, the rhoconnect-java plugin jar file is not available in Maven public repositories, so you need to manually install this jar into your Maven's local repository.
113
-
114
- Download the [Rhoconnect-java](https://github.com/downloads/rhomobile/rhoconnect-java/rhoconnect-java-1.0.1.jar) plugin jar file to your PC.
115
-
116
- Use the following Maven command to add the rhoconnect-java plugin jar file to your Java backend application. Replace `path-to-jar` with the path to where you have the rhoconnect-java plugin jar file.
62
+ You must also add the rhoconnect-java and rhoconnect-java-api jars to your Maven project. At this moment they are not available in Maven public repositories and you need install the jar manually into your Maven's local repository.
117
63
 
118
64
  :::term
119
- $ mvn install:install-file -Dfile=/path-to-jar/rhoconnect-java-1.0.1.jar -DgroupId=com.rhomobile.rhoconnect -DartifactId=rhoconnect-java -Dversion=1.0.1 -Dpackaging=jar
65
+ $ mvn install:install-file -Dfile=/path-to-jar/rhoconnect-java-api-1.0.0.jar -DgroupId=com.msi.rhoconnect.api \
66
+ -DartifactId=rhoconnect-java-api -Dversion=1.0.0 -Dpackaging=jar
67
+ $ mvn install:install-file -Dfile=/path-to-jar/rhoconnect-java-1.0.2.jar \
68
+ -DgroupId=com.rhomobile.rhoconnect -DartifactId=rhoconnect-java -Dversion=1.0.2 -Dpackaging=jar
120
69
 
121
- Now that the rhoconnect-java jar library is included in your Maven local repository, you must add it as a dependency by adding the following code to the `pom.xml` file. Make sure the version number matches the version number in the jar file name.
70
+ Now, the `rhoconnect-java` jar library is included into your Maven local repository.
71
+ In the RhoconnectJavaSample application, you would add this code to the pom.xml file.
122
72
 
123
73
  :::xml
124
74
  <!-- Rhoconnect-java plugin -->
@@ -128,26 +78,27 @@ Now that the rhoconnect-java jar library is included in your Maven local reposit
128
78
  <version>1.0.1</version>
129
79
  <type>jar</type>
130
80
  </dependency>
81
+ <!-- Rhoconnect-java-api and its dependencies -->
82
+ <dependency>
83
+ <groupId>com.msi.rhoconnect.api</groupId>
84
+ <artifactId>rhoconnect-java-api</artifactId>
85
+ <version>1.0.0</version>
86
+ <type>jar</type>
87
+ </dependency>
88
+ <dependency>
89
+ <groupId>com.sun.jersey</groupId>
90
+ <artifactId>jersey-bundle</artifactId>
91
+ <version>1.17</version>
92
+ </dependency>
93
+ <dependency>
94
+ <groupId>com.googlecode.json-simple</groupId>
95
+ <artifactId>json-simple</artifactId>
96
+ <version>1.1.1</version>
97
+ </dependency>
98
+
99
+ ### Updating Your Servlet XML Configuration File
131
100
 
132
- ### Creating the rhoconnect-java Plugin Jar File from the rhoconnect-java Repository
133
-
134
- Instead of downloading the rhoconnect-java plugin jar file, you can generate it from sources by cloning the `rhoconnect-java` repository:
135
-
136
- :::term
137
- $ git clone https://github.com/rhomobile/rhoconnect-java.git
138
-
139
- and executing the following commands in your cloned rhoconnect-java project directory:
140
-
141
- :::term
142
- $ mvn clean
143
- $ mvn compile
144
- $ mvn jar:jar
145
-
146
- The archived `rhoconnect-java-x.y.z.jar` file will be created in the project's `target` directory.
147
-
148
- ## Updating Your Servlet XML Configuration File
149
-
150
- Update your servlet xml configuration file in your Java backend application folder to include rhoconnect-java metadata: the packages, converters, and beans. In your Java application folder (such as the RhoconnectJavaSample folder), add the following code to `src/main/webapp/WEB-INF/spring-servlet.xml`.
101
+ Update your servlet xml configuration file to include rhoconnect-java metadata: the packages, converters, and beans. In the RhoconnectJavaSample, the following code is added to src/main/webapp/WEB-INF/spring-servlet.xml file.
151
102
 
152
103
  :::xml
153
104
  <!-- rhoconnect-java plugin packages -->
@@ -180,46 +131,43 @@ Update your servlet xml configuration file in your Java backend application fold
180
131
  <!-- rhoconnect-java plugin beans -->
181
132
  <bean id="dispatcher" class = "com.rhomobile.rhoconnect.RhoconnectDispatcher"></bean>
182
133
  <bean id="rhoconnectClient" class = "com.rhomobile.rhoconnect.RhoconnectClient" init-method="setAppEndpoint" >
183
- <property name="restTemplate"><ref bean="restTemplate"/></property>
184
- <property name="endpointUrl" value="<your_rhoconnect_server_url>" />
185
- <property name="appEndpoint" value=app_endpoint_url" />
186
- <property name="apiToken" value="api_token" />
134
+ <property name="endpointUrl" value="your_rhoconnect_server_url" />
135
+ <property name="appEndpoint" value="your_spring_app_url" />
136
+ <property name="apiToken" value="my-rhoconnect-token" />
187
137
  </bean>
188
138
 
189
139
  <!--The following bean handles the application's authentication routine and should be implemented by you -->
190
140
  <bean id="authenticate" class = "com.rhomobile.contact.ContactAuthenticate" />
191
141
 
192
- ### Configuring Properties in the setAppEndpoint Method
193
-
194
142
  The `setAppEndpoint` method in the `rhoconnectClient` bean in the above code sample is a main point in establishing the communication
195
- link between the `Rhoconnect` server and your Java Spring 3 MVC backend application. It has the following properties that you need to configure.
143
+ link between the `Rhoconnect` server and the Spring 3 MVC application. It has the following properties that you need to configure.
196
144
 
197
145
  <table border="1">
198
146
  <tr>
199
- <td><code>your_rhoconnect_server_url</code></td>
147
+ <td><code>endpointUrl</code></td>
200
148
  <td>rhoconnect server's url, for example <code>http://localhost:9292</code></td>
201
149
  </tr>
202
150
  <tr>
203
- <td><code>app_endpoint_url</code></td>
151
+ <td><code>appEndpoint</code></td>
204
152
  <td>your Spring 3 MVC app url, for example <code>http://localhost:8080/contacts</code></td>
205
153
  </tr>
206
154
  <tr>
207
155
  <td><code>apiToken</code></td>
208
- <td>rhoconnect server's api_token, for example <code>rhoconnect_api_token</code></td>
156
+ <td>rhoconnect server's api_token, for example <code>my-rhoconnect-token</code></td>
209
157
  </tr>
210
158
  </table>
211
159
 
212
- The `authenticate` bean will be called by the RhoConnect server to authenticate users, so it has to implement the `Rhoconnect` interface provided by the rhoconnect-java plugin:
160
+ The `authenticate` bean will be called by rhoconnect server to authenticate users, and has to implement `Rhoconnect` interface provided by rhoconnect-java plugin:
213
161
 
214
162
  :::java
215
163
  package com.rhomobile.rhoconnect;
216
164
  import java.util.Map;
217
165
 
218
166
  public interface Rhoconnect {
219
- String authenticate(String userName, String password, Map<String, Object> attributes);
167
+ String authenticate(String userName, String password, Map<String, Object> attributes);
220
168
  }
221
169
 
222
- For example, in the RhoConnectJavaSample example, in `src/main/java/com/rhomobile/contact/ContactAuthenticate.java`, you can code the ContactAuthentication class as follows, replacing the TODO comment with authentication code (this example just returns "app").
170
+ For example:
223
171
 
224
172
  :::java
225
173
  package com.rhomobile.contact;
@@ -233,22 +181,22 @@ For example, in the RhoConnectJavaSample example, in `src/main/java/com/rhomobil
233
181
 
234
182
  @Override
235
183
  public String authenticate(String login, String password, Map<String, Object> attributes) {
236
- logger.debug("ContactAuthenticate#authenticate: implement your authentication code!");
237
- // TODO: your authentication code goes here ...
238
- // Return null value if authentication fails.
184
+ logger.debug("ContactAuthenticate#authenticate: implement your authentication code!");
185
+ // TODO: your authentication code goes here ...
186
+ // Return null value if authentication fails.
239
187
 
240
- // Otherwise, returned value is data partitioning: i.e. user name for filtering data on per user basis
241
- //return login;
188
+ // Otherwise, returned value is data partitioning: i.e. user name for filtering data on per user basis
189
+ //return login;
242
190
 
243
- // But if you want your data to be partitioned by 'app' (i.e. the data will be shared among all users),
244
- // you should return string "app": it will instruct Rhoconnect to partition the data accordingly.
245
- return "app";
191
+ // But if you want your data to be partitioned by app (i.e. the data will be shared among all users),
192
+ // you should return string "app": it will instruct Rhoconnect to partition the data accordingly.
193
+ return "app";
246
194
  }
247
195
  }
248
196
 
249
- ## Establishing communication from the RhoConnect server to the java backend application
197
+ ### Establishing communication from the RhoConnect server to java back-end application
250
198
 
251
- You need to establish communication from the RhoConnect instance to your java backend application by mixing the RhoconnectResource interface in your data access (DAO) service class. This interface is in the Java plugin, `rhoconnect-java/src/main/java/com/rhomobile/rhoconnect/RhoconnectResource.java`. (Note that you do not change the code in `RhoconnectResource.java`.)
199
+ You need to establish communication from the RhoConnect instance to your java back-end application by mixing RhoconnectResource interface in your data access (DAO) service class:
252
200
 
253
201
  :::java
254
202
  package com.rhomobile.rhoconnect;
@@ -259,84 +207,37 @@ You need to establish communication from the RhoConnect instance to your java ba
259
207
  Map<String, Object> rhoconnectQuery(String partition);
260
208
  Integer rhoconnectCreate(String partition, Map<String, Object> attributes);
261
209
  Integer rhoconnectUpdate(String partition, Map<String, Object> attributes);
262
- Integer rhoconnectDelete(String partition, Map<String, Object> attributes);
210
+ Integer rhoconnetDelete(String partition, Map<String, Object> attributes);
263
211
  }
264
212
 
265
- To help the rhoconnect-java plugin correctly map the model name to the service bean, you should take into account the following conventions when you write the code in your Java backend application to establish communication to the RhoConnect server:
213
+ To help rhoconnect-java plugin correctly do mapping of model name to service bean you should take into account the following conventions:
266
214
 
267
- * The name of the DAO service bean (class) in your java backend application should be the model name followed by `ServiceImpl` suffix (i. e. `ContactServiceImpl` for model `Contact`)
268
- * The service bean should be auto-wired into the corresponding controller via @Autowired annotation
215
+ * Name of the DAO service bean (class) should be model name followed by `ServiceImpl` suffix (i. e. `ContactServiceImpl` for model `Contact`)
216
+ * Service bean should be auto-wired into corresponding controller via @Autowired annotation
269
217
 
270
218
  Data partitioning in your code should be based on filtering data for unique user (i.e. your user name) or per application (shared dataset for all users).
271
- For more information about RhoConnect partitions, please refer to the [RhoConnect docs](http://docs.rhomobile.com/rhoconnect/source-adapters#data-partitioning).
272
-
273
- ## Establishing communication from java backend application to the RhoConnect server
274
-
275
- You must establish the communication from your java backend application to the RhoConnect server by auto-wiring the `RhoconnectClient` bean into your DAO service class and inserting notifications hooks into the data access (create/update/delete) methods.
276
-
277
- After you generate a Sprint 3.0 MVC application, you have a DAO service class similar to the RhoconnectJavaSample file of `ContactServiceImpl.java`, located in `src/main/java/com/rhomobile/contact/service`.
219
+ For more information about RhoConnect partitions, please refer to the [RhoConnect docs](http://docs.rhomobile.com/rhosync/source-adapters#data-partitioning).
278
220
 
279
- :::java
280
- package com.rhomobile.contact.service;
281
-
282
- import java.util.List;
283
-
284
- import org.springframework.beans.factory.annotation.Autowired;
285
- import org.springframework.stereotype.Service;
286
- import org.springframework.transaction.annotation.Transactional;
287
-
288
- import com.rhomobile.contact.dao.ContactDAO;
289
- import com.rhomobile.contact.form.Contact;
290
-
291
- @Service
292
- public class ContactServiceImpl implements ContactService {
293
-
294
- @Autowired
295
- private ContactDAO contactDAO;
296
-
297
- @Transactional
298
- public int addContact(Contact contact) {
299
- return contactDAO.addContact(contact);
300
- }
301
-
302
- @Transactional
303
- public List<Contact> listContact() {
304
- return contactDAO.listContact();
305
- }
306
-
307
- @Transactional
308
- public void removeContact(Integer id) {
309
- contactDAO.removeContact(id);
310
- }
311
-
312
- @Transactional
313
- public Contact getContact(Integer id) {
314
- return contactDAO.getContact(id);
315
- }
316
-
317
- @Transactional
318
- public void updateContact(Contact contact) {
319
- contactDAO.updateContact(contact);
320
- }
321
- }
221
+ ### Establishing communication from java back-end application to the RhoConnect server
322
222
 
223
+ You also must to establish the communication from your java back-end application to the RhoConnect instance by auto-wiring `RhoconnectClient` bean into your DAO service class and inserting notifications hooks into data access (create/update/delete) methods.
323
224
  `RhoconnectClient` bean is provided by rhoconnect-java plugin and responds to the following methods you have to call:
324
225
 
325
226
  * boolean notifyOnCreate(String sourceName, Object objId, Object object)
326
227
  * boolean notifyOnUpdate(String sourceName, Object objId, Object object)
327
228
  * boolean notifyOnDelete(String sourceName, Object objId)
328
229
 
329
- Here is an example of how you would recode the ContactServiceImpl.java for the `RhoconnectJavaSample` application. Comments are added to show where you add new code to import libraries such as `RhoconnectClient` and `RhoconnectResource`, and where you call the notifyOnCreate, notifyOnDelete, and notifyOnUpdate methods to tell the backend about changes from the RhoConnect server, and where you implement the rhoconnectQuery, rhoconnectCreate, rhoconnectUpdate, and rhoconnectDelete methods to communicate changes in the backend to the RhoConnect server.
230
+ Example for `RhoconnectJavaSample` application:
330
231
 
331
- :::java
232
+ :::java
332
233
  package com.rhomobile.contact.service;
333
234
 
334
- import java.util.HashMap; /* import HashMap */
335
- import java.util.Iterator; /* import Iterator */
235
+ import java.util.HashMap;
236
+ import java.util.Iterator;
336
237
  import java.util.List;
337
- import java.util.Map; /* import Map */
238
+ import java.util.Map;
338
239
 
339
- import org.apache.commons.beanutils.BeanUtils; /* import BeanUtils */
240
+ import org.apache.commons.beanutils.BeanUtils;
340
241
  import org.springframework.beans.factory.annotation.Autowired;
341
242
  import org.springframework.stereotype.Service;
342
243
  import org.springframework.transaction.annotation.Transactional;
@@ -344,24 +245,19 @@ Here is an example of how you would recode the ContactServiceImpl.java for the `
344
245
  import com.rhomobile.contact.dao.ContactDAO;
345
246
  import com.rhomobile.contact.form.Contact;
346
247
 
347
- /* import RhoconnectClient bean and RhoconnectResource bean */
348
248
  import com.rhomobile.rhoconnect.RhoconnectClient;
349
249
  import com.rhomobile.rhoconnect.RhoconnectResource;
350
250
 
351
- /* add RhoConnectResource to class implementation */
352
251
  @Service
353
252
  public class ContactServiceImpl implements ContactService, RhoconnectResource {
354
253
  //private static final Logger logger = Logger.getLogger(ContactServiceImpl.class);
355
254
 
356
255
  @Autowired
357
256
  private ContactDAO contactDAO;
358
-
359
- /* Add the RhoconnectClient bean via autowire */
360
257
  @Autowired
361
258
  private RhoconnectClient client;
362
259
  private static final String sourceName = "Contact"; // name of DAO model
363
260
 
364
- /* Call the notifyOnCreate method from RhoconnectClient bean to tell the backend of changes from RhoConnect server */
365
261
  @Transactional
366
262
  public int addContact(Contact contact) {
367
263
  int id = contactDAO.addContact(contact);
@@ -369,14 +265,12 @@ Here is an example of how you would recode the ContactServiceImpl.java for the `
369
265
  return id;
370
266
  }
371
267
 
372
- /* Call the notifyOnUpdate method from RhoconnectClient bean to tell the backend of changes from RhoConnect server */
373
268
  @Transactional
374
269
  public void updateContact(Contact contact) {
375
270
  contactDAO.updateContact(contact);
376
271
  client.notifyOnUpdate(sourceName, Integer.toString(contact.getId()), contact);
377
272
  }
378
273
 
379
- /* Call the notifyOnDelete method from RhoconnectClient bean to tell the backend of changes from RhoConnect server */
380
274
  @Transactional
381
275
  public void removeContact(Integer id) {
382
276
  contactDAO.removeContact(id);
@@ -393,7 +287,6 @@ Here is an example of how you would recode the ContactServiceImpl.java for the `
393
287
  return contactDAO.getContact(id);
394
288
  }
395
289
 
396
- /* Implement the rhoconnectQuery method to communicate query in backend to the RhoConnect server */
397
290
  @Override
398
291
  @Transactional
399
292
  public Map<String, Object> rhoconnectQuery(String partition) {
@@ -408,7 +301,6 @@ Here is an example of how you would recode the ContactServiceImpl.java for the `
408
301
  return h;
409
302
  }
410
303
 
411
- /* Implement the rhoconnectCreate method to communicate create in backend to the RhoConnect server */
412
304
  @Override
413
305
  @Transactional
414
306
  public Integer rhoconnectCreate(String partition, Map<String, Object> attributes) {
@@ -423,7 +315,6 @@ Here is an example of how you would recode the ContactServiceImpl.java for the `
423
315
  return null;
424
316
  }
425
317
 
426
- /* Implement the rhoconnectUpdate method to communicate updates in backend to the RhoConnect server */
427
318
  @Override
428
319
  @Transactional
429
320
  public Integer rhoconnectUpdate(String partition, Map<String, Object> attributes) {
@@ -439,10 +330,9 @@ Here is an example of how you would recode the ContactServiceImpl.java for the `
439
330
  return null;
440
331
  }
441
332
 
442
- /* Implement the rhoconnectDelete method to communicate delete in backend to the RhoConnect server */
443
333
  @Override
444
334
  @Transactional
445
- public Integer rhoconnectDelete(String partition, Map<String, Object> attributes) {
335
+ public Integer rhoconnetDelete(String partition, Map<String, Object> attributes) {
446
336
  String objId = (String)attributes.get("id");
447
337
  Integer id = Integer.parseInt(objId);
448
338
  removeContact(id);
@@ -450,7 +340,292 @@ Here is an example of how you would recode the ContactServiceImpl.java for the `
450
340
  }
451
341
  }
452
342
 
453
- Click [here](https://github.com/shurab/RhoconnectJavaPluginDemo) to download the full source code of a Contact manager application with rhoconnect-java plugin.
343
+ Click [here](https://github.com/shurab/RhoconnectJavaPluginDemo) to download full source code of Contact manager application with rhoconnect-java plugin.
344
+
345
+ ## RhoConnect-Java-API
346
+
347
+ The rhoconnect-java project contains `java-api` module that provides Java API to all resources available in <a href='http://docs.rhomobile.com/rhoconnect/rest-api'>Rhoconnect</a>.
348
+ The `rhoconnect-java-api`is a generic Java library for communicating with RhoConnect RESTful API and it might be used to implement java client apps or components of back-end servers.
349
+ This library also is used by RhoConnect-Java plugin to directly access RhoConnect resources.
350
+
351
+ The library has the following dependencies:
352
+
353
+ * [jersey java](http://jersey.java.net/)
354
+ * [json-simple](http://code.google.com/p/json-simple)
355
+
356
+ Every usage of API call follows this pattern:
357
+
358
+ :::java
359
+ ClientResponse response = NameOfResource.method(serverUrl, params);
360
+ // Every call returns as a response Jersey object
361
+ // To get status code call `response.getStatus()`
362
+ // To get body as a jason string call `response.getEntity(String.class)`
363
+
364
+ ### SystemResource
365
+
366
+ #### `POST /rc/v1/system/login`
367
+ Login to the RhoConnect server and get API token.
368
+
369
+ :::java
370
+ public static ClientResponse login(String url, String password);
371
+
372
+ #### `POST /rc/v1/system/reset`
373
+ Reset the server: flush db and re-bootstrap server.
374
+
375
+ :::java
376
+ public static ClientResponse reset(String url, String token);
377
+
378
+ #### `GET /rc/v1/system/license`
379
+ Returns license information of the currently used license.
380
+
381
+ :::java
382
+ public static ClientResponse license(String url, String token);
383
+
384
+ #### `GET /rc/v1/system/appserver`
385
+ Returns the url of the plugin’s backend from the RhoConnect server.
386
+
387
+ :::java
388
+ public static ClientResponse getAppserver(String url, String token);
389
+
390
+ #### `POST /rc/v1/system/appserver`
391
+ Saves the url of the plugin’s backend to the RhoConnect server.
392
+
393
+ :::java
394
+ public static ClientResponse setAppserver(String url, String token, String adapterUrl)
395
+
396
+ #### `GET /rc/v1/system/stats`
397
+ Retrieves stats for a given metric key.
398
+
399
+ :::java
400
+ public static ClientResponse statsMetricKey(String url, String token, String metricKey, int start, int finish)
401
+
402
+ Retrieves a list of metric keys matching a given pattern. This supports ‘glob’ or ‘*’ style pattern matching.
403
+
404
+ :::java
405
+ public static ClientResponse statsMetricPattern(String url, String token, String pattern);
406
+
407
+
408
+ ### StoreResource
409
+
410
+ #### `GET /rc/v1/store/:doc`
411
+ Return content of a given document stored in Redis.
412
+
413
+ :::java
414
+ public static ClientResponse get(String url, String token, String docname);
415
+
416
+
417
+ #### `POST /rc/v1/store/:doc`
418
+ Sets the content of the specified server document. Data should be a string.
419
+ If append flag is set to true , the data is appended to the current doc (if it exists)
420
+ instead of replacing it.
421
+
422
+ :::java
423
+ public static ClientResponse set(String url, String token, String docname, String data, boolean append);
424
+
425
+ ### UserResource
426
+
427
+ #### `GET /rc/v1/users`
428
+ List users registered with this RhoConnect application.
429
+
430
+ :::java
431
+ public static ClientResponse list(String url, String token);
432
+
433
+ #### `POST /rc/v1/users`
434
+ Create a user in this RhoConnect application.
435
+
436
+ :::java
437
+ public static ClientResponse create(String url, String token, String login, String password);
438
+
439
+ #### `DELETE /rc/v1/users/:user_id`
440
+ Delete User and all associated devices from the RhoConnect application.
441
+
442
+ :::java
443
+ public static ClientResponse delete(String url, String token, String userId);
444
+
445
+ #### `PUT /rc/v1/users/:user_id`
446
+ Update attributes for a user on this RhoConnect application.
447
+ userAttributes is a hash of attribute/value pairs:
448
+ {:a_user_specific_attribute => a_user_specific_attribute_value}.
449
+
450
+ :::java
451
+ public static ClientResponse update(String url, String token, String userId, JSONObject userAttributes);
452
+
453
+ #### `GET /rc/v1/users/:user_id`
454
+ Returns the information for the specified user.
455
+
456
+ :::java
457
+ public static ClientResponse show(String url, String token, String userId);
458
+
459
+ #### `GET /rc/v1/users/:user_id/clients`
460
+ List clients (devices) associated with given user.
461
+
462
+ :::java
463
+ public static ClientResponse listClients(String url, String token, String userId);
464
+
465
+ #### `DELETE /rc/v1/users/:user_id/clients/:client_id`
466
+ Deletes the specified client (device) for the given user.
467
+
468
+ :::java
469
+ public static ClientResponse deleteClient(String url, String token, String userId, String clientId);
470
+
471
+ #### `GET /rc/v1/users/:user_id/sources/:source_id/docnames`
472
+ Return list of document keys associated with given source and user.
473
+ If userId set to '*', this call will return list of keys for 'shared' documents.
474
+
475
+ :::java
476
+ public static ClientResponse sourcesDocnames(String url, String token, String userId, String sources);
477
+
478
+ #### `POST /rc/v1/users/ping`
479
+ Sends PUSH message to all devices of the specified user(s).
480
+ pingParams is a hash of the following attribute/pairs:
481
+ { "user_id":[array_of_users], "sources":"source_name",
482
+ "message": "hello world", "vibrate": 2000, "sound": "hello.mp3" }
483
+
484
+ :::java
485
+ public static ClientResponse ping(String url, String token, JSONObject pingParams);
486
+
487
+ #### `GET /rc/v1/users/:user_id/sources/:source_id/docs/:doc`
488
+ Return content of a given source document for the specified user.
489
+
490
+ :::java
491
+ public static ClientResponse getSourcesDocs(String url, String token, String userId, String sourceId, String docname);
492
+
493
+ #### `POST /rc/v1/users/:user_id/sources/:source_id/docs/:doc`
494
+ Sets the content of the specified source document for the given user.
495
+ Data should be either a string or hash of hashes.
496
+ If append flag is set to true , the data is appended to the current doc (if it exists)
497
+ instead of replacing it.
498
+
499
+ :::java
500
+ public static ClientResponse setSourcesDocs(String url, String token, String userId, String sourceId,
501
+ String docname, String data, boolean append);
502
+ public static ClientResponse setSourcesDocs(String url, String token, String userId, String sourceId,
503
+ String docname, JSONObject data, boolean append);
504
+
505
+ ### SourceResource
506
+
507
+ #### `GET /rc/v1/sources/type/:partition_type`
508
+ Return list of source adapters for this RhoConnect application for the given partition type.
509
+ Partition type is one of PartitionType.App, PartitionType.User, PartitionType.All.
510
+
511
+ :::java
512
+ public static ClientResponse getSources(String url, String token, PartitionType partitionType);
513
+
514
+ #### `GET /rc/v1/sources/:source_id`
515
+ Return attributes associated with a given source.
516
+
517
+ :::java
518
+ public static ClientResponse getAttributes(String url, String token, String sourceId);
519
+
520
+ #### `PUT /rc/v1/sources/:source_id`
521
+ Updates attributes associated with a given source. Attributes defined as a hash of attribute/value pair(s).
522
+
523
+ :::java
524
+ public static ClientResponse setAttributes(String url, String token, String sourceId, JSONObject sourceParams);
525
+
526
+ ### ClientResource
527
+
528
+ #### `GET /rc/v1/clients/:client_id`
529
+ Returns client (device) attributes, such as device_type, device_pin, device_port.
530
+
531
+ :::java
532
+ public static ClientResponse getAttributes(String url, String token, String clientId);
533
+
534
+ #### `GET /rc/v1/clients/:client_id/sources/:source_id/docnames`
535
+ Returns list of document keys associated with particular client for a given source.
536
+
537
+ :::java
538
+ public static ClientResponse getSourcesDocnames(String url, String token, String clientId, String sourceId);
539
+
540
+ #### `GET /rc/v1/clients/:client_id/sources/:source_id/docs/:doc`
541
+ Return content of a given source document for the specified client.
542
+
543
+ :::java
544
+ public static ClientResponse getSourceDocument(String url, String token, String clientId, String sourceId, String docname);
545
+
546
+ #### `POST /rc/v1/clients/:client_id/sources/:source_id/docnames`
547
+ Sets the content of the specified source document for the given client.
548
+ Data should be either a string or hash of hashes. If append flag is set to true,
549
+ the data is appended to the current doc (if it exists) instead of replacing it.
550
+
551
+ :::java
552
+ public static ClientResponse setSourcesDocnames(String url, String token, String clientId, String sourceId,
553
+ String data, boolean append);
554
+ public static ClientResponse setSourcesDocnames(String url, String token, String clientId, String sourceId,
555
+ JSONObject data, boolean append);
556
+
557
+ ### PluginResource
558
+
559
+ #### `POST /app/v1/:source_name/push_objects`
560
+ Push new objects or object updates to RhoConnect.
561
+
562
+ :::java
563
+ public static ClientResponse pushObjects(String url, String token, String userId, String sourceName, JSONObject data);
564
+
565
+ #### `POST /app/v1/:source_name/push_deletes`
566
+ Delete objects from RhoConnect.
567
+
568
+ :::java
569
+ public static ClientResponse deleteObjects(String url, String token, String userId, String sourceName, JSONArray objectIds);
570
+
571
+ ### ReadStateResource
572
+
573
+ #### `PUT /rc/v1/readstate/users/:user_id/sources/:source_id`
574
+ Sets source poll interval to “current time plus x seconds”.
575
+ Calling method with refreshTime = null will trigger a refresh on the sync request for the source.
576
+
577
+ :::java
578
+ public static ClientResponse setPollInterval(String url, String token, String userId, String sourceName, Integer refreshTime);
579
+
580
+
581
+ ### Sample of Java RhoConnect client app
582
+
583
+ :::java
584
+ import com.msi.rhoconnect.api.SystemResource;
585
+ import com.msi.rhoconnect.api.UserResource;
586
+ import com.sun.jersey.api.client.ClientResponse;
587
+ import org.json.simple.JSONArray;
588
+ import org.json.simple.JSONValue;
589
+
590
+ public class JavaClient {
591
+ static String URL = "http://localhost:9292";
592
+
593
+ public static void main(String[] args) {
594
+ try {
595
+ ClientResponse response = SystemResource.login(URL, "");
596
+ if(response.getStatus() == 200) {
597
+ String token = response.getEntity(String.class);
598
+ System.out.println("Login to server. Got API token: " + token);
599
+
600
+ // List users registered with this RhoConnect application
601
+ response = UserResource.list(URL, token);
602
+ JSONArray users = (JSONArray)JSONValue.parse(response.getEntity(String.class));
603
+ System.out.println(users);
604
+
605
+ // Create "testuser" in this RhoConnect application
606
+ response = UserResource.create(URL, token, "testuser", "password");
607
+
608
+ // Make sure that 'testuser' is registered
609
+ response = UserResource.list(URL, token);
610
+ users = (JSONArray)JSONValue.parse(response.getEntity(String.class));
611
+ if(users.contains("testuser"))
612
+ System.out.println("User 'testuser' created");
613
+ System.out.println(users);
614
+
615
+ // ....
616
+
617
+ // Delete "testuser" from this rhoconnect app
618
+ response = UserResource.delete(URL, token, "testuser");
619
+ if (response.getStatus() == 200)
620
+ System.out.println("User 'testuser' deleted");
621
+ }
622
+ } catch (Exception e) {
623
+ // TODO Auto-generated catch block
624
+ e.printStackTrace();
625
+ }
626
+ }
627
+ }
628
+
454
629
 
455
630
  ## Meta
456
631
  Created and maintained by Alexander Babichev.