7 Replies Latest reply on Mar 27, 2013 9:28 AM by Cristian Quintero

    How sync my RhoApplication to a PC database?

      Hi,

       

      I am starting in Rho Elements.. i just made a Rho Application for the ET1 but i want now to synchronize the data to a local database through wi-fi... ia have read the rho connect tutorial but what i cannot understand is how the RhoConnect project matches or link with the RhoApplication Project... I developed the Inventory Managment application... what steps should i follow to link those projects? or what is the relationship...

       

      I can develop my rest service on the PC exposes it... but i don´t understand totally RhoConnect.

       

      Thanks,

       

      Cristian

        • Re: How sync my RhoApplication to a PC database?
          Hector Meza

          Cristian, at a high level the mobile application sysnc's its data with rhoconnect via the defined Rhom models. 

          On the mobile application you 1) specifgy the location of rhoconnect in the rhoconfig.txt file then for each model 2) you flag the model to enable sync  i.e. "Product" model would have a product.rb file where you enable.

           

          Now in the rhoconnect application, you would define a source adaptor (or plugin) which must have the Same name as each of the models that the application defined i.e. "Product".  When a sync occurs, the application is looking for the matching names.

           

          this is high level but as for your question on how the link of app to rhoconnect know what to sync = name of the model matches the source adaptor name.

           

          I would suggest you look at the tutorial that sync's the product table - heroku has a webservice with shared data that helps to test this out.

           

          http://docs.rhomobile.com/rhoconnect/tutorial

            • Re: How sync my RhoApplication to a PC database?

              Hi Hector...

               

              Thanks for your input... then i could say that the rho application and the rho connecte app are two differents application, each one of those with its own depoyment over the device and running the rhoconnect it would look just into the data layer of the respective model?

                • Re: How sync my RhoApplication to a PC database?
                  Hector Meza

                  Cristian, yes the RhoElements application (mobile app) and Rhoconnect are two different application but the mobile application is scaffolded for Rhoconnect sync.  The mobile app can sync thru rhoconnect or you can write your own sync, rhoconnect can also work with not Rhoelements application - you can sync to Java, Obc C etc  apps. 

                   

                  For a  mobile app that uses rhoconnect - the application is registered by rhoconnect on its inital sync.  Rhoconnect them manages the sync updates of each model for a specific device, and also maintains the sync with your backend data.  The mobile device does not talk directly to the backend.  Rhoconnect will have a consistant connect with the backend so your data is upto date, as devices are connecting/updating they will keep a seperate data thread which manages the indiviual device updates (gives you a lot of flexibility for on/off line connection).

                   

                  Hope this helps clarify - as for data flow, take a look at sync work flow diagram (Rhodes Reference - synchronization), there is a diagram that shows the data flow.

                   

                  http://docs.rhomobile.com/rhodes/synchronization

                    • Re: How sync my RhoApplication to a PC database?

                      Well.. couple of days without checking this... i install the rhoconnect push apk file.. first time i run the app i got an error like "user not authenticated"... then i thought that putting in comments all code of the login method and just leave SyncEngine.dosync.. but it obviously was not smart as i know got nothing... at least the last error was telling me that the sync process seems to be running...

                       

                      Where is that login being managed? my REST service is not requesting for login.. .any ideas?

                      • Re: How sync my RhoApplication to a PC database?

                        Well.. after have dedicated time to read the tutorials and documentation.. i have advanced and i have fixed some concepts i had misunderstood... now i am getting communication with the sync server and i am doing rspecs on my source adapter as i cannot get the info passed to the device yet...

                         

                        This is the json i am getting from my REST service...{"inventory":[{"image":"2","name":"3","sku":"1"},{"image":"5","name":"6","sku":"40"},{"image":"56","name":"3","sku":"45"},{"image":"9","name":"38","sku":"7"},{"image":"955","name":"3568","sku":"766"},{"image":"9545","name":"35568","sku":"7666"}]} and I am getting an error in the code of the source adapter of the tutorial... this is what rspecs says...

                         

                        Failures:

                         

                          1) Inventory it should behave like SpecHelper should process Inventory query

                             ←[31mFailure/Error:←[0m ←[31m@result[item["inventory"]["sku"]] = item["inv

                        ntory"]←[0m

                             ←[31mTypeError:←[0m

                               ←[31mcan't convert String into Integer←[0m

                         

                        Cannot understand why is that error... any ideas?

                          • Re: How sync my RhoApplication to a PC database?
                            Pietro Francesco Maggi

                            Hi Cristian,

                            I suppose that you're working inside the query method in your source adapter.

                            To pass the data from the RhoConnect source adapter to your device app you need to build a Result hash of hashes with the format:

                             

                                # TODO: Query your backend data source and assign the records

                                # to a nested hash structure called @result. For example:

                                # @result = {

                                #   "1"=>{"name"=>"Acme", "industry"=>"Electronics"},

                                #   "2"=>{"name"=>"Best", "industry"=>"Software"}

                                # }

                             

                            In your case, you can use a couple of gems to get the data from your backend system:

                            require 'json'

                            require 'rest_client'

                             

                            Set the base address of your RESTful web service in the initialize method:

                              def initialize(source)

                                @webservice_returning_json_url = 'http://...'

                                super(source)

                              end

                             

                            And retrive the data from the backend system in your query method, building the nested hashes structure you need:

                              def query(params=nil)

                                parsed = JSON.parse(RestClient.get("#{@webservice_returning_json_url}").body)

                             

                                 @result={}

                                parsed.each do |item|

                                  @result[item["inventory"]["sku"].to_s] = item["inventory"]

                                end if parsed

                              end

                             

                            Ciao

                            Pietro

                              • Re: How sync my RhoApplication to a PC database?

                                Hi Petro,

                                 

                                Thanks for your reply... well that is the confusing I am doing excatly what you have stated.. in fact this is my method.. which is the same than in the tutorial but i get the error at line @result[item["inventory"]["sku"].to_s] = item["inventory"] and i Have tried with item["inventory"]["sku"].to_s] and item["inventory"]["sku"]]

                                 

                                it

                                "should process Inventory query" do     

                                     @base = 'http://10.186.5.247:8080/SyncAgentWS/webresources/synccenter.inventory'

                                      rest_result = RestClient.get("#{@base}").body         


                                              if rest_result.code != 200              

                                                    raise SourceAdapterException.new("Error connecting!")             

                                              end


                                              parsed = JSON.parse(rest_result)

                                               @result={}

                                              parsed.each do |item|               

                                                     @result[item["inventory"]["sku"].to_s] = item["inventory"]

                                              end if parsed

                                    end