Search in sources :

Example 1 with GeoSQLiteMessageStore

use of org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore in project mobile-messaging-sdk-android by infobip.

the class MessageStoreTest method test_shouldUseGeoSqlStoreForGeo_whenConfiguredWithoutMessageStore.

@Test
public void test_shouldUseGeoSqlStoreForGeo_whenConfiguredWithoutMessageStore() {
    MobileMessagingCore.setMessageStoreClass(context, null);
    assertTrue(new GeofencingHelper(context).getMessageStoreForGeo() instanceof GeoSQLiteMessageStore);
}
Also used : GeofencingHelper(org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper) GeoSQLiteMessageStore(org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore) Test(org.junit.Test)

Example 2 with GeoSQLiteMessageStore

use of org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore in project mobile-messaging-sdk-android by infobip.

the class GeofencingImpl method removeExpiredAreasFromStorage.

void removeExpiredAreasFromStorage() {
    GeoSQLiteMessageStore messageStoreForGeo = (GeoSQLiteMessageStore) geofencingHelper.getMessageStoreForGeo();
    List<Message> messages = messageStoreForGeo.findAll(context);
    List<String> messageIdsToDelete = new ArrayList<>(messages.size());
    Date now = new Date();
    for (Message message : messages) {
        Geo geo = GeoDataMapper.geoFromInternalData(message.getInternalData());
        if (geo == null) {
            continue;
        }
        List<Area> areasList = geo.getAreasList();
        Date expiryDate = geo.getExpiryDate();
        if (areasList == null || areasList.isEmpty()) {
            continue;
        }
        for (Area area : areasList) {
            if (!area.isValid() || expiryDate == null) {
                continue;
            }
            if (expiryDate.before(now)) {
                messageIdsToDelete.add(message.getMessageId());
            }
        }
    }
    if (!messageIdsToDelete.isEmpty()) {
        messageStoreForGeo.deleteByIds(context, messageIdsToDelete.toArray(new String[] {}));
    }
}
Also used : Geo(org.infobip.mobile.messaging.geo.Geo) Area(org.infobip.mobile.messaging.geo.Area) Message(org.infobip.mobile.messaging.Message) ArrayList(java.util.ArrayList) GeoSQLiteMessageStore(org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore) Date(java.util.Date)

Example 3 with GeoSQLiteMessageStore

use of org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore in project mobile-messaging-sdk-android by infobip.

the class MessageStoreTest method test_shouldUseGeoSqlStoreForGeo_whenConfiguredWithMessageStore.

@Test
public void test_shouldUseGeoSqlStoreForGeo_whenConfiguredWithMessageStore() {
    MobileMessagingCore.setMessageStoreClass(context, TestMessageStore.class);
    assertTrue(new GeofencingHelper(context).getMessageStoreForGeo() instanceof GeoSQLiteMessageStore);
}
Also used : GeofencingHelper(org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper) GeoSQLiteMessageStore(org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore) Test(org.junit.Test)

Aggregations

GeoSQLiteMessageStore (org.infobip.mobile.messaging.geo.storage.GeoSQLiteMessageStore)3 GeofencingHelper (org.infobip.mobile.messaging.geo.geofencing.GeofencingHelper)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Message (org.infobip.mobile.messaging.Message)1 Area (org.infobip.mobile.messaging.geo.Area)1 Geo (org.infobip.mobile.messaging.geo.Geo)1