Search in sources :

Example 1 with PlaceNotFoundException

use of ve.com.abicelis.remindy.exception.PlaceNotFoundException in project Remindy by abicelis.

the class RemindyDAO method getPlace.

/**
 * Returns a Place given a placeId.
 * @param placeId The id of the place
 */
public Place getPlace(int placeId) throws PlaceNotFoundException, SQLiteConstraintException {
    SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
    Cursor cursor = db.query(RemindyContract.PlaceTable.TABLE_NAME, null, RemindyContract.PlaceTable._ID + "=?", new String[] { String.valueOf(placeId) }, null, null, null);
    if (cursor.getCount() == 0)
        throw new PlaceNotFoundException("Specified Place not found in the database. Passed id=" + placeId);
    if (cursor.getCount() > 1)
        throw new SQLiteConstraintException("Database UNIQUE constraint failure, more than one record found. Passed value=" + placeId);
    cursor.moveToNext();
    return getPlaceFromCursor(cursor);
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) PlaceNotFoundException(ve.com.abicelis.remindy.exception.PlaceNotFoundException) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) Cursor(android.database.Cursor)

Example 2 with PlaceNotFoundException

use of ve.com.abicelis.remindy.exception.PlaceNotFoundException in project Remindy by abicelis.

the class GeofenceNotificationIntentService method getGeofenceNotificationTitle.

private String getGeofenceNotificationTitle(int geofenceTransition, Geofence triggeringGeofence) {
    String transition = "";
    switch(geofenceTransition) {
        case Geofence.GEOFENCE_TRANSITION_ENTER:
            transition = getResources().getString(R.string.notification_service_geofence_enter);
            break;
        case Geofence.GEOFENCE_TRANSITION_EXIT:
            transition = getResources().getString(R.string.notification_service_geofence_exit);
            break;
        case Geofence.GEOFENCE_TRANSITION_DWELL:
            // transition = getResources().getString(R.string.notification_service_geofence_dwell);
            transition = getResources().getString(R.string.notification_service_geofence_enter);
            break;
    }
    int placeId = Integer.valueOf(triggeringGeofence.getRequestId());
    try {
        Place place = new RemindyDAO(this).getPlace(placeId);
        return String.format(Locale.getDefault(), getResources().getString(R.string.notification_service_geofence_title), transition, place.getAlias());
    } catch (PlaceNotFoundException e) {
        return "";
    }
}
Also used : PlaceNotFoundException(ve.com.abicelis.remindy.exception.PlaceNotFoundException) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Place(ve.com.abicelis.remindy.model.Place)

Example 3 with PlaceNotFoundException

use of ve.com.abicelis.remindy.exception.PlaceNotFoundException in project Remindy by abicelis.

the class RemindyDAO method getReminderOfTask.

/**
 * Returns a Reminder given its taskId and reminderType
 * @param taskId The ID of the task
 * @param reminderType The Type of reminder
 */
public Reminder getReminderOfTask(int taskId, @NonNull ReminderType reminderType) throws CouldNotGetDataException, SQLiteConstraintException {
    SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
    Reminder reminder;
    String tableName, whereClause;
    switch(reminderType) {
        case ONE_TIME:
            whereClause = RemindyContract.OneTimeReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
            tableName = RemindyContract.OneTimeReminderTable.TABLE_NAME;
            break;
        case REPEATING:
            whereClause = RemindyContract.RepeatingReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
            tableName = RemindyContract.RepeatingReminderTable.TABLE_NAME;
            break;
        case LOCATION_BASED:
            whereClause = RemindyContract.LocationBasedReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
            tableName = RemindyContract.LocationBasedReminderTable.TABLE_NAME;
            break;
        default:
            throw new CouldNotGetDataException("ReminderType is invalid. Type=" + reminderType);
    }
    Cursor cursor = db.query(tableName, null, whereClause, new String[] { String.valueOf(taskId) }, null, null, null);
    try {
        if (cursor.getCount() == 0)
            throw new CouldNotGetDataException("Specified Reminder not found in the database. Passed id=" + taskId);
        if (cursor.getCount() > 1)
            throw new SQLiteConstraintException("Database UNIQUE constraint failure, more than one Reminder found. Passed id=" + taskId);
        cursor.moveToNext();
        switch(reminderType) {
            case ONE_TIME:
                reminder = getOneTimeReminderFromCursor(cursor);
                break;
            case REPEATING:
                reminder = getRepeatingReminderFromCursor(cursor);
                break;
            case LOCATION_BASED:
                reminder = getLocationBasedReminderFromCursor(cursor);
                int placeId = ((LocationBasedReminder) reminder).getPlaceId();
                try {
                    ((LocationBasedReminder) reminder).setPlace(getPlace(placeId));
                } catch (PlaceNotFoundException | SQLiteConstraintException e) {
                    throw new CouldNotGetDataException("Error trying to get Place for Location-based Reminder", e);
                }
                break;
            default:
                throw new CouldNotGetDataException("ReminderType is invalid. Type=" + reminderType);
        }
    } finally {
        cursor.close();
    }
    return reminder;
}
Also used : CouldNotGetDataException(ve.com.abicelis.remindy.exception.CouldNotGetDataException) RepeatingReminder(ve.com.abicelis.remindy.model.reminder.RepeatingReminder) Reminder(ve.com.abicelis.remindy.model.reminder.Reminder) LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) OneTimeReminder(ve.com.abicelis.remindy.model.reminder.OneTimeReminder) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) LocationBasedReminder(ve.com.abicelis.remindy.model.reminder.LocationBasedReminder) PlaceNotFoundException(ve.com.abicelis.remindy.exception.PlaceNotFoundException) SQLiteConstraintException(android.database.sqlite.SQLiteConstraintException) Cursor(android.database.Cursor)

Aggregations

PlaceNotFoundException (ve.com.abicelis.remindy.exception.PlaceNotFoundException)3 Cursor (android.database.Cursor)2 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 RemindyDAO (ve.com.abicelis.remindy.database.RemindyDAO)1 CouldNotGetDataException (ve.com.abicelis.remindy.exception.CouldNotGetDataException)1 Place (ve.com.abicelis.remindy.model.Place)1 LocationBasedReminder (ve.com.abicelis.remindy.model.reminder.LocationBasedReminder)1 OneTimeReminder (ve.com.abicelis.remindy.model.reminder.OneTimeReminder)1 Reminder (ve.com.abicelis.remindy.model.reminder.Reminder)1 RepeatingReminder (ve.com.abicelis.remindy.model.reminder.RepeatingReminder)1