Synchronize data - Tuong-Nguyen/PreparationEduLog GitHub Wiki
Requirements
Data is synchronized by two ways:
- Application to Server
- Server to application
Application to Server
They are realtime data:
- Route progress
- Driver/Bus/Student actions, for example: driver log in/ log out, bus start run/end run, student on board/disembark,...
What to do?
Network is connected
- Route progress is sent to the server as soon as it happens
- Events data are sent to server are:
- LOG_IN
- LOG_OUT
- PASSWORD_CHANGE
- ASSIGN_BUS (PM mode)
- DEASSIGN_BUS (PM mode)
- START_RUN
- END_RUN
- NO_MOTION_BEGIN
- NO_MOTION_END
- CREATE_NEW_STOP
- STOP_BEGIN (Begin servicing a stop, board/disembark students)
- STOP_END
- STUDENT_BOARD
- STUDENT_DISEMBARK
- RAW_EVENT
Network is disconnected
- All data are saved as cache
Network is reconnected
- Push cached data to server.
Server to application
They are cached data:
- Selected route info
- New route info
What to do?
Network is connected
- When driver selects a route, it's info should be saved as cache data
Network is disconnected
- Driver can select a route from cached routes
- Driver can build and use new route with a temporary id
Network is reconnected
- New route with temporary id will be pushed to server and query for a new id.
Expectation
- A sample http request module to get or send data to server. It's used for testing sync data service. It has 2 parts:
- Implementation
- Interface for other service to communicate
- A service to synchronize data get from or send data to http request module
Application to Server
- Input get from (client):
- Activity
- Motion detection
- Connection change notification
- There are components:
ContentProvider
: stores the data get from clientService
: polling about 5s to get data fromContentProvider
and send to server
Server to Application
It can be a SyncAdapter framework: https://github.com/googlesamples/android-BasicSyncAdapter
Testing
There are some behavior test cases to ensure the solution works:
- Input from activity, motion detection, connection change is mocked
- Http request module is mocked
- Expect Http request module's send or get data method is called:
- For each 5s if it's realtime data
- For each 1h if it's cached data