Skip to content

ServerStorage

rarrouba edited this page Jul 24, 2017 · 2 revisions

Description

This class inherits from the interface StorageComponent and handles all the communication to the backend specifically for the running statistics of the user.

Constructor

This class is used in ServerSynchronization to synchronize the local data on the phone with the data on the server. When the constructor is called the setUserToken() method is called. This method provides the class with the user token through firebase. This token will be used on our backend server to verify users.

Connection

The connect() method provides the data from the server using a POST-request. The body of that request contains the token. The response contains an 'edit_time' variable. This variable indicates the last time the statistics were updated on the server. If the user has never been saved in the database, then the edit_time is 0 and the response contains no statistics.

Disconnection

The disconnect() method just removes the previously requested stats from the class.

Get and Save AggregateRunningStatistics

The getAggregateRunningStatistics() method generates a Gson object from the received stats. The saveAggregateRunningStatistics() method saves the stats passed by as an argument to the server using a POST-request.

Synchronization

In the SeverSynchronization class all synchronization between local and server storage is handled. The edit times of both the local and server storage are compared and based on the situation the according storage is updated. This class is then used in the PersistenceController which handles both the saving of stats and saving of runs

Remarks and future considerations

In the original version the app already contained a ServerStorage class, but because it didn't use any kind of middleware and just connected directly to the database (which is a bad idea) we rewrote the class entirely. The problem with this is that there a couple of methods that are redundant. To solve this small problem, you could consider editing the class it inherits from (StorageComponent), but then you will also have to edit the LocalStorage class and all the classes that use these as a composition.