Search in sources :

Example 6 with SpiceException

use of com.octo.android.robospice.persistence.exception.SpiceException in project robospice by stephanenicolas.

the class RequestProcessorTest method testDefaultRetryPolicy_implements_retry_countdown_and_exponential_backoff.

public void testDefaultRetryPolicy_implements_retry_countdown_and_exponential_backoff() throws Exception {
    // define local values since class constant values didn't reveal
    // incremental backoff
    final long localDelayBeforeRetry = 200;
    final float localRetryBackoffMultiplier = 5.0f;
    final int localRetryCount = 3;
    // given
    DefaultRetryPolicy retryPolicy = new DefaultRetryPolicy(localRetryCount, localDelayBeforeRetry, localRetryBackoffMultiplier);
    assertEquals(localRetryCount, retryPolicy.getRetryCount());
    assertEquals(localDelayBeforeRetry, retryPolicy.getDelayBeforeRetry());
    // when
    SpiceException e = null;
    retryPolicy.retry(e);
    // then
    assertEquals(localRetryCount - 1, retryPolicy.getRetryCount());
    assertEquals((long) (localDelayBeforeRetry * localRetryBackoffMultiplier), retryPolicy.getDelayBeforeRetry());
}
Also used : SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) DefaultRetryPolicy(com.octo.android.robospice.retry.DefaultRetryPolicy)

Example 7 with SpiceException

use of com.octo.android.robospice.persistence.exception.SpiceException in project ETSMobile-Android2 by ApplETS.

the class Utility method loadNotifications.

/**
     * Gets MonÉTS notifications and update DB
     * @param context
     * @param requestListener
     */
public static void loadNotifications(Context context, final RequestListener<Object> requestListener) {
    final SecurePreferences securePreferences = new SecurePreferences(context);
    final boolean allNotifsLoaded = securePreferences.getBoolean(Constants.ALL_NOTIFS_LOADED, false);
    MonETSNotificationsRequest monETSNotificationsRequest;
    if (!allNotifsLoaded) {
        monETSNotificationsRequest = new MonETSNotificationsRequest(context, false);
    } else {
        monETSNotificationsRequest = new MonETSNotificationsRequest(context, true);
    }
    final DataManager dataManager = DataManager.getInstance(context);
    dataManager.start();
    final DatabaseHelper databaseHelper = new DatabaseHelper(context);
    dataManager.sendRequest(monETSNotificationsRequest, new RequestListener<Object>() {

        @Override
        public void onRequestFailure(SpiceException spiceException) {
            requestListener.onRequestFailure(spiceException);
            dataManager.stop();
        }

        @Override
        public void onRequestSuccess(Object o) {
            if (o instanceof MonETSNotificationList) {
                try {
                    Dao<MonETSNotification, ?> dao = databaseHelper.getDao(MonETSNotification.class);
                    MonETSNotificationList list = (MonETSNotificationList) o;
                    for (MonETSNotification monETSNotification : list) {
                        dao.createOrUpdate(monETSNotification);
                    }
                    if (!allNotifsLoaded) {
                        securePreferences.edit().putBoolean(Constants.ALL_NOTIFS_LOADED, true).commit();
                    }
                    requestListener.onRequestSuccess(list);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            dataManager.stop();
        }
    });
}
Also used : MonETSNotificationList(ca.etsmtl.applets.etsmobile.model.MonETSNotificationList) MonETSNotification(ca.etsmtl.applets.etsmobile.model.MonETSNotification) SpiceException(com.octo.android.robospice.persistence.exception.SpiceException) SQLException(java.sql.SQLException) DataManager(ca.etsmtl.applets.etsmobile.http.DataManager) Dao(com.j256.ormlite.dao.Dao) MonETSNotificationsRequest(ca.etsmtl.applets.etsmobile.http.MonETSNotificationsRequest) DatabaseHelper(ca.etsmtl.applets.etsmobile.db.DatabaseHelper)

Aggregations

SpiceException (com.octo.android.robospice.persistence.exception.SpiceException)7 RequestCancelledException (com.octo.android.robospice.exception.RequestCancelledException)2 SQLException (java.sql.SQLException)2 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 DatabaseHelper (ca.etsmtl.applets.etsmobile.db.DatabaseHelper)1 AppletsApiEvenementsRequest (ca.etsmtl.applets.etsmobile.http.AppletsApiEvenementsRequest)1 AppletsApiSourcesRequest (ca.etsmtl.applets.etsmobile.http.AppletsApiSourcesRequest)1 DataManager (ca.etsmtl.applets.etsmobile.http.DataManager)1 MonETSNotificationsRequest (ca.etsmtl.applets.etsmobile.http.MonETSNotificationsRequest)1 SignetsMobileSoap (ca.etsmtl.applets.etsmobile.http.soap.SignetsMobileSoap)1 WebServiceSoap (ca.etsmtl.applets.etsmobile.http.soap.WebServiceSoap)1 ArrayOfFicheEmploye (ca.etsmtl.applets.etsmobile.model.ArrayOfFicheEmploye)1 ArrayOfService (ca.etsmtl.applets.etsmobile.model.ArrayOfService)1 Etudiant (ca.etsmtl.applets.etsmobile.model.Etudiant)1 FicheEmploye (ca.etsmtl.applets.etsmobile.model.FicheEmploye)1 ListeDeSessions (ca.etsmtl.applets.etsmobile.model.ListeDeSessions)1 MonETSNotification (ca.etsmtl.applets.etsmobile.model.MonETSNotification)1 MonETSNotificationList (ca.etsmtl.applets.etsmobile.model.MonETSNotificationList)1